MCPcopy Create free account
hub / github.com/kataras/iris / Err

Method Err

x/errors/errors.go:304–335  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

302// In exception, if the given "err" is a type of validation error
303// then the Validation method is called instead.
304func (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.

Callers 2

HandleErrorFunction · 0.95
BindMethod · 0.45

Calls 4

ValidationMethod · 0.95
MessageMethod · 0.95
StopWithJSONMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected