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:
Luís Murta 2025-08-24 23:25:24 +01:00
parent 6b5a07aac0
commit 786bf589d0
Signed by: satprog
GPG Key ID: 169EF1BBD7049F94

View File

@ -21,7 +21,7 @@ func (server *ServerImpl) GetBanks(ctx echo.Context) error {
banks, err := server.Dal.Banks()
if err != nil {
return ctx.NoContent(http.StatusInternalServerError)
return err
}
if len(banks) == 0 {
@ -36,8 +36,7 @@ func (server *ServerImpl) GetBankById(ctx echo.Context, bankId string) error {
bank, err := server.Dal.Bank(bankId)
if err != nil {
log.Printf("%v", err)
return ctx.NoContent(http.StatusInternalServerError)
return err
}
if bank == nil {
@ -78,8 +77,7 @@ func (server *ServerImpl) GetTransactionById(ctx echo.Context, transactionId int
transaction, err := server.Dal.Transaction(transactionId)
if err != nil {
log.Printf("%v", err)
return ctx.NoContent(http.StatusInternalServerError)
return err
}
if transaction == nil {
@ -98,8 +96,7 @@ func (server *ServerImpl) CreateTransaction(ctx echo.Context) error {
transaction, err := server.Dal.InsertTransaction(transaction2entity(*t))
if err != nil {
log.Printf("%v", err)
return ctx.NoContent(http.StatusInternalServerError)
return err
}
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 {
if exists, err := server.Dal.TransactionExists(entity.TransactionId(transactionId)); err != nil {
log.Printf("%v", err)
return ctx.NoContent(http.StatusInternalServerError)
return err
} else if !exists {
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)
if err != nil {
log.Printf("%v", err)
return ctx.NoContent(http.StatusInternalServerError)
return err
}
if !success {
@ -134,7 +129,7 @@ func (server *ServerImpl) UpdateTransaction(ctx echo.Context, transactionId int6
func (server *ServerImpl) GetCategories(ctx echo.Context) error {
categories, err := server.Dal.Categories()
if err != nil {
return ctx.NoContent(http.StatusInternalServerError)
return err
}
if len(categories) == 0 {