mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-09-27 03:56:51 +02:00
Move panic handling out of router
This commit is contained in:
@@ -19,7 +19,6 @@ var (
|
||||
)
|
||||
|
||||
type RouteHandler func(string, http.ResponseWriter, *http.Request)
|
||||
type PanicHandler func(string, http.ResponseWriter, *http.Request, error)
|
||||
|
||||
type route struct {
|
||||
Method string
|
||||
@@ -29,9 +28,8 @@ type route struct {
|
||||
}
|
||||
|
||||
type Router struct {
|
||||
prefix string
|
||||
Routes []*route
|
||||
PanicHandler PanicHandler
|
||||
prefix string
|
||||
Routes []*route
|
||||
}
|
||||
|
||||
func (r *route) isMatch(req *http.Request) bool {
|
||||
@@ -95,16 +93,6 @@ func (r *Router) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
replaceRemoteAddr(req, ip)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if rerr := recover(); rerr != nil {
|
||||
if err, ok := rerr.(error); ok && r.PanicHandler != nil {
|
||||
r.PanicHandler(reqID, rw, req, err)
|
||||
} else {
|
||||
panic(rerr)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
LogRequest(reqID, req)
|
||||
|
||||
for _, rr := range r.Routes {
|
||||
|
Reference in New Issue
Block a user