X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=kraftakt.go;fp=kraftakt.go;h=4c6945903e78d5fa376a036c3ee4d291b5d964a4;hb=79cc9f9d92197e7286c166978401f99c679932c2;hp=61a576edf720a6df71e700d4762eca6c6a2f069d;hpb=e6dd37c95e5524e9e6136c14d7c1b577a971cd04;p=kraftakt.git diff --git a/kraftakt.go b/kraftakt.go index 61a576e..4c69459 100644 --- a/kraftakt.go +++ b/kraftakt.go @@ -43,6 +43,12 @@ func init() { templates = t } +func internalServerError(ctx context.Context, w http.ResponseWriter, err error) { + log.Errorf(ctx, "%v", err) + + http.Error(w, "Internal Server Error\n\nReference: "+appengine.RequestID(ctx), http.StatusInternalServerError) +} + // ContextHandler implements http.Handler type ContextHandler func(context.Context, http.ResponseWriter, *http.Request) error @@ -50,12 +56,12 @@ func (hndl ContextHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { ctx := appengine.NewContext(r) if err := app.LoadConfig(ctx); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) + internalServerError(ctx, w, fmt.Errorf("LoadConfig() = %v", err)) return } if err := hndl(ctx, w, r); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) + internalServerError(ctx, w, err) return } } @@ -66,7 +72,7 @@ func (hndl AuthenticatedHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques ctx := appengine.NewContext(r) if err := app.LoadConfig(ctx); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) + internalServerError(ctx, w, fmt.Errorf("LoadConfig() = %v", err)) return } @@ -74,7 +80,7 @@ func (hndl AuthenticatedHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques if gaeUser == nil { url, err := user.LoginURL(ctx, r.URL.String()) if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) + internalServerError(ctx, w, fmt.Errorf("LoginURL() = %v", err)) return } http.Redirect(w, r, url, http.StatusTemporaryRedirect) @@ -83,12 +89,12 @@ func (hndl AuthenticatedHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques u, err := app.NewUser(ctx, gaeUser.Email) if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) + internalServerError(ctx, w, fmt.Errorf("NewUser(%q) = %v", gaeUser.Email, err)) return } if err := hndl(ctx, w, r, u); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) + internalServerError(ctx, w, err) return } }