Check status code when calling the subscription API.
authorFlorian Forster <ff@octo.it>
Wed, 10 Jan 2018 13:52:33 +0000 (14:52 +0100)
committerFlorian Forster <ff@octo.it>
Wed, 10 Jan 2018 13:52:33 +0000 (14:52 +0100)
gfitsync.go

index 7d90df6..614d513 100644 (file)
@@ -152,6 +152,12 @@ 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 = ""