refactor: return err from API handlers
Instead of logging + NoContent(http.StatusIntervalServerError). Gin already logs the error when returned and returns a 500 to the client.
This commit is contained in:
parent
6b5a07aac0
commit
786bf589d0
@ -21,7 +21,7 @@ func (server *ServerImpl) GetBanks(ctx echo.Context) error {
|
|||||||
|
|
||||||
banks, err := server.Dal.Banks()
|
banks, err := server.Dal.Banks()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ctx.NoContent(http.StatusInternalServerError)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(banks) == 0 {
|
if len(banks) == 0 {
|
||||||
@ -36,8 +36,7 @@ func (server *ServerImpl) GetBankById(ctx echo.Context, bankId string) error {
|
|||||||
|
|
||||||
bank, err := server.Dal.Bank(bankId)
|
bank, err := server.Dal.Bank(bankId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%v", err)
|
return err
|
||||||
return ctx.NoContent(http.StatusInternalServerError)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if bank == nil {
|
if bank == nil {
|
||||||
@ -78,8 +77,7 @@ func (server *ServerImpl) GetTransactionById(ctx echo.Context, transactionId int
|
|||||||
|
|
||||||
transaction, err := server.Dal.Transaction(transactionId)
|
transaction, err := server.Dal.Transaction(transactionId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%v", err)
|
return err
|
||||||
return ctx.NoContent(http.StatusInternalServerError)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if transaction == nil {
|
if transaction == nil {
|
||||||
@ -98,8 +96,7 @@ func (server *ServerImpl) CreateTransaction(ctx echo.Context) error {
|
|||||||
|
|
||||||
transaction, err := server.Dal.InsertTransaction(transaction2entity(*t))
|
transaction, err := server.Dal.InsertTransaction(transaction2entity(*t))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%v", err)
|
return err
|
||||||
return ctx.NoContent(http.StatusInternalServerError)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.JSON(http.StatusCreated, entity2transaction(transaction))
|
return ctx.JSON(http.StatusCreated, entity2transaction(transaction))
|
||||||
@ -107,8 +104,7 @@ func (server *ServerImpl) CreateTransaction(ctx echo.Context) error {
|
|||||||
|
|
||||||
func (server *ServerImpl) UpdateTransaction(ctx echo.Context, transactionId int64) error {
|
func (server *ServerImpl) UpdateTransaction(ctx echo.Context, transactionId int64) error {
|
||||||
if exists, err := server.Dal.TransactionExists(entity.TransactionId(transactionId)); err != nil {
|
if exists, err := server.Dal.TransactionExists(entity.TransactionId(transactionId)); err != nil {
|
||||||
log.Printf("%v", err)
|
return err
|
||||||
return ctx.NoContent(http.StatusInternalServerError)
|
|
||||||
} else if !exists {
|
} else if !exists {
|
||||||
return ctx.NoContent(http.StatusNotFound)
|
return ctx.NoContent(http.StatusNotFound)
|
||||||
}
|
}
|
||||||
@ -121,8 +117,7 @@ func (server *ServerImpl) UpdateTransaction(ctx echo.Context, transactionId int6
|
|||||||
|
|
||||||
success, err := server.Dal.UpdateTransaction(entity.TransactionId(transactionId), update.Category)
|
success, err := server.Dal.UpdateTransaction(entity.TransactionId(transactionId), update.Category)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%v", err)
|
return err
|
||||||
return ctx.NoContent(http.StatusInternalServerError)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !success {
|
if !success {
|
||||||
@ -134,7 +129,7 @@ func (server *ServerImpl) UpdateTransaction(ctx echo.Context, transactionId int6
|
|||||||
func (server *ServerImpl) GetCategories(ctx echo.Context) error {
|
func (server *ServerImpl) GetCategories(ctx echo.Context) error {
|
||||||
categories, err := server.Dal.Categories()
|
categories, err := server.Dal.Categories()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ctx.NoContent(http.StatusInternalServerError)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(categories) == 0 {
|
if len(categories) == 0 {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user