mirror of
https://github.com/kataras/iris.git
synced 2025-12-17 09:57:01 +00:00
new Application.SetContextErrorHandler method
This commit is contained in:
24
iris.go
24
iris.go
@@ -59,6 +59,8 @@ type Application struct {
|
||||
*router.Router
|
||||
router.HTTPErrorHandler // if Router is Downgraded this is nil.
|
||||
ContextPool *context.Pool
|
||||
// See SetContextErrorHandler, defaults to nil.
|
||||
contextErrorHandler context.ErrorHandler
|
||||
|
||||
// config contains the configuration fields
|
||||
// all fields defaults to something that is working, developers don't have to set it.
|
||||
@@ -429,6 +431,28 @@ func (app *Application) GetContextPool() *context.Pool {
|
||||
return app.ContextPool
|
||||
}
|
||||
|
||||
// SetContextErrorHandler can optionally register a handler to handle
|
||||
// and fire a customized error body to the client on JSON write failures.
|
||||
//
|
||||
// ExampleCode:
|
||||
//
|
||||
// type contextErrorHandler struct{}
|
||||
// func (e *contextErrorHandler) HandleContextError(ctx iris.Context, err error) {
|
||||
// errors.InvalidArgument.Err(ctx, err)
|
||||
// }
|
||||
// ...
|
||||
// app.SetContextErrorHandler(new(contextErrorHandler))
|
||||
func (app *Application) SetContextErrorHandler(errHandler context.ErrorHandler) *Application {
|
||||
app.contextErrorHandler = errHandler
|
||||
return app
|
||||
}
|
||||
|
||||
// GetContextErrorHandler returns the handler which handles errors
|
||||
// on JSON write failures.
|
||||
func (app *Application) GetContextErrorHandler() context.ErrorHandler {
|
||||
return app.contextErrorHandler
|
||||
}
|
||||
|
||||
// ConfigureHost accepts one or more `host#Configuration`, these configurators functions
|
||||
// can access the host created by `app.Run` or `app.Listen`,
|
||||
// they're being executed when application is ready to being served to the public.
|
||||
|
||||
Reference in New Issue
Block a user