Err sends the error's text as a message to the client. In exception, if the given "err" is a type of validation error then the Validation method is called instead.
(ctx *context.Context, err error)
| 302 | // In exception, if the given "err" is a type of validation error |
| 303 | // then the Validation method is called instead. |
| 304 | func (e ErrorCodeName) Err(ctx *context.Context, err error) { |
| 305 | if err == nil { |
| 306 | return |
| 307 | } |
| 308 | |
| 309 | if vErr, ok := err.(ValidationError); ok { |
| 310 | if vErr == nil { |
| 311 | return // consider as not error for any case, this should never happen. |
| 312 | } |
| 313 | |
| 314 | e.Validation(ctx, vErr) |
| 315 | } |
| 316 | |
| 317 | if vErrs, ok := err.(ValidationErrors); ok { |
| 318 | if len(vErrs) == 0 { |
| 319 | return // consider as not error for any case, this should never happen. |
| 320 | } |
| 321 | |
| 322 | e.Validation(ctx, vErrs...) |
| 323 | } |
| 324 | |
| 325 | // If it's already an Error type then send it directly. |
| 326 | if httpErr, ok := err.(*Error); ok { |
| 327 | if errorCode, ok := errorCodeMap[e]; ok { |
| 328 | httpErr.ErrorCode = errorCode |
| 329 | ctx.StopWithJSON(errorCode.Status, httpErr) // here we override the fail function and send the error as it is. |
| 330 | return |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | e.Message(ctx, err.Error()) |
| 335 | } |
| 336 | |
| 337 | // Log sends an error of "format" and optional "args" to the client and prints that |
| 338 | // error using the "LogError" package-level function, which can be customized. |
no test coverage detected