trying to fix the marshall error
@@ -88,24 +88,13 @@ func (t *RoundTripper) RoundTrip(req *http.Request) (resp *http.Response, err er
}(resp.Body)
bodyBytes, _ = ioutil.ReadAll(resp.Body)
- marshalErr := json.Unmarshal(bodyBytes, &newSession)
-
- // Restore the io.ReadCloser to its original state
- resp.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
-
- if marshalErr != nil {
- return resp, marshalErr
- }
-
- if newSession.AccessToken == "" {
- return resp, nil
- }
-
+ if marshalErr := json.Unmarshal(bodyBytes, &newSession); marshalErr == nil {
+ if newSession.AccessToken != "" {
tokenURL := url.URL{Scheme: req.URL.Scheme, Host: req.URL.Host, Path: req.URL.Path}
log.WithField("token_url", tokenURL.String()).Debug("Looking for OAuth provider who issued the token")
oAuthServer, err := t.oAuthServersRepo.FindByTokenURL(tokenURL)
if err != nil {
- log.Error("Failed to find OAuth server by token URL: ", err)
+ log.Error("Failed to find OAuth server by token URL", err)
} else {
newSession.OAuthServerID = oAuthServer.ID
@@ -113,6 +102,11 @@ func (t *RoundTripper) RoundTrip(req *http.Request) (resp *http.Response, err er
t.manager.Set(newSession.AccessToken, newSession, newSession.ExpiresIn)
}
}
+ }
+
+ // Restore the io.ReadCloser to its original state
+ resp.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
+ }
return resp, err
}
