ApiOutputError writes a JSON error message to the HTTP response body
(c *gin.Context, err error)
| 90 | |
| 91 | // ApiOutputError writes a JSON error message to the HTTP response body |
| 92 | func ApiOutputError(c *gin.Context, err error) { |
| 93 | if e, ok := err.(errors.Error); ok { |
| 94 | logruslog.Global.Error(err, "HTTP %d error", e.GetType().GetHttpCode()) |
| 95 | messages := e.Messages() |
| 96 | c.JSON(e.GetType().GetHttpCode(), &ApiBody{ |
| 97 | Success: false, |
| 98 | Message: e.Error(), |
| 99 | Causes: messages.Causes(), |
| 100 | }) |
| 101 | } else { |
| 102 | logruslog.Global.Error(err, "HTTP %d error (native)", http.StatusInternalServerError) |
| 103 | c.JSON(http.StatusInternalServerError, &ApiBody{ |
| 104 | Success: false, |
| 105 | Message: err.Error(), |
| 106 | }) |
| 107 | } |
| 108 | c.Writer.Header().Set("Content-Type", "application/json") |
| 109 | } |
| 110 | |
| 111 | // ApiOutputSuccess writes a JSON success message to the HTTP response body |
| 112 | func ApiOutputSuccess(c *gin.Context, body interface{}, status int) { |
nothing calls this directly
no test coverage detected