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

Unified Diff: milo/appengine/settings/themes.go

Issue 2525493002: Milo: Add themed page for errors (Closed)
Patch Set: Review Created 4 years 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 | « milo/appengine/frontend/templates/buildbot/pages/error.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: milo/appengine/settings/themes.go
diff --git a/milo/appengine/settings/themes.go b/milo/appengine/settings/themes.go
index 23bdc2c114155e3b86c3e115d86a4f46b566cd94..ecc976e0299c2e252f7012422a3733872ce2141d 100644
--- a/milo/appengine/settings/themes.go
+++ b/milo/appengine/settings/themes.go
@@ -83,11 +83,13 @@ func GetTemplateBundles() []NamedBundle {
DefaultTemplate: name,
DebugMode: info.IsDevAppServer,
DefaultArgs: func(c context.Context) (templates.Args, error) {
- loginURL, err := auth.LoginURL(c, "/")
+ r := getRequest(c)
+ path := r.URL.Path
+ loginURL, err := auth.LoginURL(c, path)
if err != nil {
return nil, err
}
- logoutURL, err := auth.LogoutURL(c, "/")
+ logoutURL, err := auth.LogoutURL(c, path)
if err != nil {
return nil, err
}
@@ -102,6 +104,7 @@ func GetTemplateBundles() []NamedBundle {
"LogoutURL": logoutURL,
"CurrentTime": clock.Now(c),
"Analytics": analytics.Snippet(c),
+ "RequestID": info.RequestID(c),
}, nil
},
FuncMap: funcMap,
@@ -172,17 +175,27 @@ func Wrap(h ThemedHandler) router.Handler {
theme := GetTheme(c.Context, c.Request)
template := h.GetTemplateName(theme)
+ // Inject the request into the context.
+ c.Context = WithRequest(c.Context, c.Request)
+
// Do the things.
args, err := h.Render(c.Context, c.Request, c.Params)
// Throw errors.
// TODO(hinoka): Add themes and templates for errors so they look better.
if err != nil {
- if merr, ok := err.(*miloerror.Error); ok {
- http.Error(c.Writer, merr.Message, merr.Code)
- } else {
- http.Error(c.Writer, err.Error(), http.StatusInternalServerError)
+ msg := err.Error()
+ code := http.StatusInternalServerError
+ if merr, ok := err.(miloerror.Error); ok {
+ msg = merr.Message
+ code = merr.Code
}
+ c.Writer.WriteHeader(code)
+ name := "pages/error.html"
+ themedMustRender(c.Context, c.Writer, theme.Name, name, templates.Args{
+ "Code": code,
+ "Message": msg,
+ })
return
}
@@ -191,3 +204,17 @@ func Wrap(h ThemedHandler) router.Handler {
themedMustRender(c.Context, c.Writer, theme.Name, name, *args)
}
}
+
+// The context key
+var requestKey = "http.request"
+
+func WithRequest(c context.Context, r *http.Request) context.Context {
+ return context.WithValue(c, &requestKey, r)
+}
+
+func getRequest(c context.Context) *http.Request {
+ if req, ok := c.Value(&requestKey).(*http.Request); ok {
+ return req
+ }
+ panic("No http.request found in context")
+}
« no previous file with comments | « milo/appengine/frontend/templates/buildbot/pages/error.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698