(ms i18n.MessageSource)
| 122 | } |
| 123 | |
| 124 | func apiResultHandler(ms i18n.MessageSource) func(*gin.Context) { |
| 125 | return func(c *gin.Context) { |
| 126 | SetMessageSource(c, ms) |
| 127 | c.Next() |
| 128 | if len(c.Errors) == 0 { |
| 129 | result, exists := GetResult(c) |
| 130 | if exists { |
| 131 | writeJSON(c, ms, http.StatusOK, result) |
| 132 | } |
| 133 | return |
| 134 | } |
| 135 | e := c.Errors[0] |
| 136 | code := 500 |
| 137 | result := types.M{ |
| 138 | "message": e.Err.Error(), |
| 139 | } |
| 140 | if re, ok := e.Err.(err.Error); ok { |
| 141 | code = re.Code() |
| 142 | } |
| 143 | if red, ok := e.Err.(err.ErrorWithData); ok { |
| 144 | result["data"] = red.Data() |
| 145 | } |
| 146 | writeJSON(c, ms, code, result) |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | func handlePanic(c *gin.Context, err any) { |
| 151 | var msg string |
no test coverage detected