X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=kraftakt.go;h=4c6945903e78d5fa376a036c3ee4d291b5d964a4;hb=79cc9f9d92197e7286c166978401f99c679932c2;hp=8d562996688c99d5fecb12bb23dcbbd6ae8dbd76;hpb=5b245cc42860c980c321c1c1829cdc373d53ac53;p=kraftakt.git diff --git a/kraftakt.go b/kraftakt.go index 8d56299..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 } } @@ -171,21 +177,9 @@ func fitbitDisconnectHandler(ctx context.Context, w http.ResponseWriter, r *http return err } - var errs appengine.MultiError - - for _, collection := range []string{"activities", "sleep"} { - if err := c.Unsubscribe(ctx, collection); err != nil { - errs = append(errs, fmt.Errorf("Unsubscribe(%q) = %v", collection, err)) - continue - } - log.Infof(ctx, "Successfully unsubscribed from %q", collection) - } - - if err := c.DeleteToken(ctx); err != nil { - errs = append(errs, fmt.Errorf("DeleteToken() = %v", err)) - } - if len(errs) != 0 { - return errs + if err := c.UnsubscribeAll(ctx); err != nil { + log.Errorf(ctx, "UnsubscribeAll() = %v", err) + return fmt.Errorf("deleting all subscriptions failed") } redirectURL := r.URL