mirror of
https://github.com/kataras/iris.git
synced 2026-02-28 05:26:00 +00:00
HandleHTTPError MVC Method as requested at #1595. Read HISTORY.md
example at: https://github.com/kataras/iris/tree/master/_examples/mvc/error-handler-http
This commit is contained in:
@@ -84,6 +84,10 @@ var BuiltinDependencies = []*Dependency{
|
||||
NewDependency(func(ctx *context.Context) net.IP {
|
||||
return net.ParseIP(ctx.RemoteAddr())
|
||||
}).Explicitly(),
|
||||
// Status Code (special type for MVC HTTP Error handler to not conflict with path parameters)
|
||||
NewDependency(func(ctx *context.Context) Code {
|
||||
return Code(ctx.GetStatusCode())
|
||||
}).Explicitly(),
|
||||
// payload and param bindings are dynamically allocated and declared at the end of the `binding` source file.
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,9 @@ type (
|
||||
// ErrorHandlerFunc implements the `ErrorHandler`.
|
||||
// It describes the type defnition for an error function handler.
|
||||
ErrorHandlerFunc func(*context.Context, error)
|
||||
|
||||
// Code is a special type for status code.
|
||||
Code int
|
||||
)
|
||||
|
||||
// HandleError fires when a non-nil error returns from a request-scoped dependency at serve-time or the handler itself.
|
||||
|
||||
@@ -88,9 +88,7 @@ func makeStruct(structPtr interface{}, c *Container, partyParamsCount int) *Stru
|
||||
newContainer := c.Clone()
|
||||
// Add the controller dependency itself as func dependency but with a known type which should be explicit binding
|
||||
// in order to keep its maximum priority.
|
||||
newContainer.Register(s.Acquire).
|
||||
Explicitly().
|
||||
DestType = typ
|
||||
newContainer.Register(s.Acquire).Explicitly().DestType = typ
|
||||
|
||||
newContainer.GetErrorHandler = func(ctx *context.Context) ErrorHandler {
|
||||
if isErrHandler {
|
||||
|
||||
Reference in New Issue
Block a user