From e8ff3dbf90fd0659d9b0591f2a773b3543cea79a Mon Sep 17 00:00:00 2001 From: akeemphilbert Date: Wed, 21 Aug 2024 21:19:01 -0400 Subject: [PATCH] feature: made it so that when the response is not successful and a message is set then it's used as the error message to return --- rest/controllers.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rest/controllers.go b/rest/controllers.go index b89af018..dcbc4bd7 100644 --- a/rest/controllers.go +++ b/rest/controllers.go @@ -174,6 +174,13 @@ func DefaultWriteController(p *ControllerParams) echo.HandlerFunc { ctxt.Response().Header().Set("Location", response.Body.(string)) return ctxt.NoContent(response.Code) } + if !response.Success { + if response.Body == nil { + return ctxt.JSON(response.Code, map[string]interface{}{ + "message": response.Message, + }) + } + } return ctxt.JSON(response.Code, response.Body) } else { if err != nil {