StopWithError stops the handlers chain and writes the "statusCode" among with the error "err". It Calls the `SetErr` method so error handlers can access the given error. If the status code is a failure one then it will also fire the specified error code handler. If the given "err" is private then
(statusCode int, err error)
| 807 | // If the given "err" is private then the |
| 808 | // status code's text is rendered instead (unless a registered error handler overrides it). |
| 809 | func (ctx *Context) StopWithError(statusCode int, err error) { |
| 810 | if err == nil { |
| 811 | return |
| 812 | } |
| 813 | |
| 814 | ctx.SetErr(err) |
| 815 | if _, ok := err.(ErrPrivate); ok { |
| 816 | // error is private, we SHOULD not render it, |
| 817 | // leave the error handler alone to |
| 818 | // render the code's text instead. |
| 819 | ctx.StopWithStatus(statusCode) |
| 820 | return |
| 821 | } |
| 822 | |
| 823 | ctx.StopWithText(statusCode, err.Error()) |
| 824 | } |
| 825 | |
| 826 | // StopWithPlainError like `StopWithError` but it does NOT |
| 827 | // write anything to the response writer, it stores the error |