MCPcopy
hub / github.com/gofiber/fiber / DefaultErrorHandler

Function DefaultErrorHandler

app.go:623–639  ·  app.go::DefaultErrorHandler

DefaultErrorHandler that process return errors from handlers

(c Ctx, err error)

Source from the content-addressed store, hash-verified

621
622// DefaultErrorHandler that process return errors from handlers
623func DefaultErrorHandler(c Ctx, err error) error {
624 if nilerror.IsNil(err) {
625 err = nil
626 }
627
628 code := StatusInternalServerError
629 e, matched := asFiberError(err)
630 if matched && e != nil {
631 code = e.Code
632 }
633 message := utils.StatusMessage(code)
634 if err != nil && (!matched || e != nil) {
635 message = err.Error()
636 }
637 c.Set(HeaderContentType, MIMETextPlainCharsetUTF8)
638 return c.Status(code).SendString(message)
639}
640
641// asFiberError reports whether err is or wraps a *Error and returns it. A direct
642// *Error is matched alloc-free by a type assertion; wrapped or joined errors

Calls 6

IsNilFunction · 0.92
asFiberErrorFunction · 0.85
ErrorMethod · 0.65
SetMethod · 0.65
SendStringMethod · 0.65
StatusMethod · 0.65