Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(705)

Unified Diff: server/middleware/paniccatcher.go

Issue 2043423004: Make HTTP middleware easier to use (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: gaemiddleware: add middleware func for WithProd Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « server/auth/xsrf/xsrf_test.go ('k') | server/prpc/server.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: server/middleware/paniccatcher.go
diff --git a/server/middleware/paniccatcher.go b/server/middleware/paniccatcher.go
index 15486b234de6eccf6f9fb9065be765e7ebe7bfc9..f990d4d358e1f5170cabc5f3b61c5fad5c07837d 100644
--- a/server/middleware/paniccatcher.go
+++ b/server/middleware/paniccatcher.go
@@ -1,32 +1,31 @@
// Copyright 2015 The LUCI Authors. All rights reserved.
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.
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) {
+ ctx := c.Context
+ w := c.Writer
+ req := c.Request
+ defer paniccatcher.Catch(func(p *paniccatcher.Panic) {
+ log.Fields{
+ "panic.error": p.Reason,
+ }.Errorf(ctx, "Caught panic during handling of %q:\n%s", req.RequestURI, p.Stack)
- // 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 `next` 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)
+ })
+ next(c)
}
« no previous file with comments | « server/auth/xsrf/xsrf_test.go ('k') | server/prpc/server.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698