Chromium Code Reviews| Index: server/middleware/paniccatcher.go |
| diff --git a/server/middleware/paniccatcher.go b/server/middleware/paniccatcher.go |
| index 15486b234de6eccf6f9fb9065be765e7ebe7bfc9..030f1613ad4cd194b8aadf2e8086e569c3a7ad2a 100644 |
| --- a/server/middleware/paniccatcher.go |
| +++ b/server/middleware/paniccatcher.go |
| @@ -7,26 +7,22 @@ package middleware |
| import ( |
| "net/http" |
| - "github.com/julienschmidt/httprouter" |
| - "golang.org/x/net/context" |
| - |
| log "github.com/luci/luci-go/common/logging" |
| "github.com/luci/luci-go/common/paniccatcher" |
| + "github.com/luci/luci-go/server/router" |
| ) |
| // WithPanicCatcher is a middleware that catches panics, dumps stack trace to |
| // logging and returns HTTP 500. |
| -func WithPanicCatcher(h Handler) Handler { |
| - return func(c context.Context, w http.ResponseWriter, r *http.Request, p httprouter.Params) { |
| - defer paniccatcher.Catch(func(p *paniccatcher.Panic) { |
| - log.Fields{ |
| - "panic.error": p.Reason, |
| - }.Errorf(c, "Caught panic during handling of %q:\n%s", r.RequestURI, p.Stack) |
| +func WithPanicCatcher(c *router.Context, next router.Handler) { |
| + defer paniccatcher.Catch(func(p *paniccatcher.Panic) { |
| + log.Fields{ |
| + "panic.error": p.Reason, |
| + }.Errorf(c.Context, "Caught panic during handling of %q:\n%s", c.Request.RequestURI, p.Stack) |
|
Vadim Sh.
2016/06/18 16:57:20
same as in tsmon middleware: better to preserve th
nishanths
2016/06/19 02:47:02
Done. Now matches behavior at origin/master.
|
| - // Note: it may be too late to send HTTP 500 if `h` already sent |
| - // headers. But there's nothing else we can do at this point anyway. |
| - http.Error(w, "Internal Server Error. See logs.", http.StatusInternalServerError) |
| - }) |
| - h(c, w, r, p) |
| - } |
| + // Note: it may be too late to send HTTP 500 if `h` already sent |
| + // headers. But there's nothing else we can do at this point anyway. |
| + http.Error(c.Writer, "Internal Server Error. See logs.", http.StatusInternalServerError) |
| + }) |
| + next(c) |
| } |