mirror of
https://github.com/kataras/iris.git
synced 2026-02-28 05:26:00 +00:00
add some api helpers
This commit is contained in:
@@ -45,7 +45,7 @@ func CanMakeHandler(tmpl macro.Template) (needsMacroHandler bool) {
|
||||
if p.HandleError != nil {
|
||||
// Check for its type.
|
||||
if _, ok := p.HandleError.(ParamErrorHandler); !ok {
|
||||
panic(fmt.Sprintf("HandleError must be a type of func(iris.Context, int, error) but got: %T", p.HandleError))
|
||||
panic(fmt.Sprintf("HandleError input argument must be a type of func(iris.Context, int, error) but got: %T", p.HandleError))
|
||||
}
|
||||
}
|
||||
break
|
||||
|
||||
@@ -595,3 +595,17 @@ func (ms *Macros) GetTrailings() (macros []*Macro) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// SetErrorHandler registers a common type path parameter error handler.
|
||||
// The "fnHandler" MUST be a type of handler.ParamErrorHandler:
|
||||
// func(ctx iris.Context, paramIndex int, err error). It calls
|
||||
// the Macro.HandleError method for each of the "ms" entries.
|
||||
func (ms *Macros) SetErrorHandler(fnHandler interface{}) {
|
||||
for _, m := range *ms {
|
||||
if m == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
m.HandleError(fnHandler)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user