1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 02:17:05 +00:00

minor improvements

This commit is contained in:
Gerasimos (Makis) Maropoulos
2024-01-20 20:32:56 +02:00
parent 4e3c242044
commit 4eb7705fae
13 changed files with 444 additions and 116 deletions

View File

@@ -6333,11 +6333,13 @@ func (ctx *Context) GetErrPublic() (bool, error) {
// which recovers from a manual panic.
type ErrPanicRecovery struct {
ErrPrivate
Cause interface{}
Callers []string // file:line callers.
Stack []byte // the full debug stack.
RegisteredHandlers []string // file:line of all registered handlers.
CurrentHandler string // the handler panic came from.
Cause interface{}
Callers []string // file:line callers.
Stack []byte // the full debug stack.
RegisteredHandlers []string // file:line of all registered handlers.
CurrentHandlerFileLine string // the handler panic came from.
CurrentHandlerName string // the handler name panic came from.
Request string // the http dumped request.
}
// Error implements the Go standard error type.
@@ -6348,7 +6350,7 @@ func (e *ErrPanicRecovery) Error() string {
}
}
return fmt.Sprintf("%v\n%s", e.Cause, strings.Join(e.Callers, "\n"))
return fmt.Sprintf("%v\n%s\nRequest:\n%s", e.Cause, strings.Join(e.Callers, "\n"), e.Request)
}
// Is completes the internal errors.Is interface.
@@ -6357,6 +6359,15 @@ func (e *ErrPanicRecovery) Is(err error) bool {
return ok
}
func (e *ErrPanicRecovery) LogMessage() string {
logMessage := fmt.Sprintf("Recovered from a route's Handler('%s')\n", e.CurrentHandlerName)
logMessage += fmt.Sprint(e.Request)
logMessage += fmt.Sprintf("%s\n", e.Cause)
logMessage += fmt.Sprintf("%s\n", strings.Join(e.Callers, "\n"))
return logMessage
}
// IsErrPanicRecovery reports whether the given "err" is a type of ErrPanicRecovery.
func IsErrPanicRecovery(err error) (*ErrPanicRecovery, bool) {
if err == nil {

View File

@@ -111,6 +111,20 @@ type Handler = func(*Context)
// See `Handler` for more.
type Handlers = []Handler
// CopyHandlers returns a copy of "handlers" Handlers slice.
func CopyHandlers(handlers []Handler) Handlers {
handlersCp := make([]Handler, 0, len(handlers))
for _, handler := range handlers {
if handler == nil {
continue
}
handlersCp = append(handlersCp, handler)
}
return handlersCp
}
func valueOf(v interface{}) reflect.Value {
if val, ok := v.(reflect.Value); ok {
return val