ApiOutputErrorWithCustomCode writes a JSON error message to the HTTP response body
(c *gin.Context, code int, err error)
| 46 | |
| 47 | // ApiOutputErrorWithCustomCode writes a JSON error message to the HTTP response body |
| 48 | func ApiOutputErrorWithCustomCode(c *gin.Context, code int, err error) { |
| 49 | if e, ok := err.(errors.Error); ok { |
| 50 | logruslog.Global.Error(err, "HTTP %d error", e.GetType().GetHttpCode()) |
| 51 | messages := e.Messages() |
| 52 | c.JSON(e.GetType().GetHttpCode(), &ApiBody{ |
| 53 | Success: false, |
| 54 | Message: e.Error(), |
| 55 | Code: code, |
| 56 | Causes: messages.Causes(), |
| 57 | }) |
| 58 | } else { |
| 59 | logruslog.Global.Error(err, "HTTP %d error (native)", http.StatusInternalServerError) |
| 60 | c.JSON(http.StatusInternalServerError, &ApiBody{ |
| 61 | Success: false, |
| 62 | Code: code, |
| 63 | Message: err.Error(), |
| 64 | }) |
| 65 | } |
| 66 | c.Writer.Header().Set("Content-Type", "application/json") |
| 67 | } |
| 68 | |
| 69 | // ApiOutputAdvancedErrorWithCustomCode writes a JSON error message to the HTTP response body |
| 70 | func ApiOutputAdvancedErrorWithCustomCode(c *gin.Context, httpStatusCode, customBusinessCode int, err error) { |
nothing calls this directly
no test coverage detected