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

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: Update tests 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
Index: server/middleware/paniccatcher.go
diff --git a/server/middleware/paniccatcher.go b/server/middleware/paniccatcher.go
index 15486b234de6eccf6f9fb9065be765e7ebe7bfc9..e9dd41e503fbae82debdd3debc6bbc7c8b01aa26 100644
--- a/server/middleware/paniccatcher.go
+++ b/server/middleware/paniccatcher.go
@@ -7,26 +7,23 @@ 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) {
+func WithPanicCatcher() router.Handler {
+ return func(c *router.Context) {
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)
+ }.Errorf(c.Context, "Caught panic during handling of %q:\n%s", c.Request.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)
+ http.Error(c.Writer, "Internal Server Error. See logs.", http.StatusInternalServerError)
})
- h(c, w, r, p)
}
iannucci 2016/06/13 19:23:29 does this still work? I don't think this works any
}

Powered by Google App Engine
This is Rietveld 408576698