From c3c38339f36cf6ca60ba57050c0fb1efccd0a7e2 Mon Sep 17 00:00:00 2001 From: Geoffrey Ragot Date: Wed, 25 Sep 2024 23:57:07 +0200 Subject: [PATCH] feat: handle errors on create api of v1 api --- .../api/v1/controllers_transactions_create.go | 31 +++++-------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/internal/api/v1/controllers_transactions_create.go b/internal/api/v1/controllers_transactions_create.go index 7b156fe77..2c32b2ce7 100644 --- a/internal/api/v1/controllers_transactions_create.go +++ b/internal/api/v1/controllers_transactions_create.go @@ -125,32 +125,17 @@ func createTransaction(w http.ResponseWriter, r *http.Request) { switch { case errors.Is(err, &ledgercontroller.ErrInsufficientFunds{}): api.BadRequest(w, ErrInsufficientFund, err) - return + case errors.Is(err, &ledgercontroller.ErrInvalidVars{}) || + errors.Is(err, ledgercontroller.ErrCompilationFailed{}) || + errors.Is(err, &ledgercontroller.ErrMetadataOverride{}) || + errors.Is(err, ledgercontroller.ErrNoPostings): + api.BadRequest(w, ErrValidation, err) + case errors.Is(err, ledgercontroller.ErrReferenceConflict{}): + api.WriteErrorResponse(w, http.StatusConflict, ErrConflict, err) default: api.InternalServerError(w, r, err) - return } - //switch { - //case ledgercontroller.IsCommandError(err): - // //switch { - // //case command.IsErrMachine(err): - // // switch { - // // case machine.IsInsufficientFundError(err): - // // api.BadRequest(w, ErrInsufficientFund, err) - // // return - // // } - // //case command.IsInvalidTransactionError(err, command.ErrInvalidTransactionCodeConflict): - // // api.BadRequest(w, ErrConflict, err) - // // return - // //case command.IsInvalidTransactionError(err, command.ErrInvalidTransactionCodeCompilationFailed): - // // api.BadRequestWithDetails(w, ErrScriptCompilationFailed, err, backend.EncodeLink(err.Error())) - // // return - // //} - // api.BadRequest(w, ErrValidation, err) - // return - //} - //api.InternalServerError(w, r, err) - //return + return } api.Ok(w, []any{mapTransactionToV1(*res)})