Check status code when calling the subscription API.
[kraftakt.git] / gfitsync.go
index 21f764b..614d513 100644 (file)
@@ -152,8 +152,16 @@ func fitbitGrantHandler(ctx context.Context, w http.ResponseWriter, r *http.Requ
        }
        defer res.Body.Close()
 
+       if res.StatusCode >= 400 {
+               data, _ := ioutil.ReadAll(r.Body)
+               log.Errorf(ctx, "creating subscription failed: status %d %q", res.StatusCode, data)
+               return fmt.Errorf("creating subscription failed")
+       }
+
        redirectURL := r.URL
        redirectURL.Path = "/"
+       redirectURL.RawQuery = ""
+       redirectURL.Fragment = ""
        http.Redirect(w, r, redirectURL.String(), http.StatusTemporaryRedirect)
        return nil
 }