Skip to content

Commit

Permalink
Break an infinite loop of retry/failure when fetch returns a 400 but …
Browse files Browse the repository at this point in the history
…client is not revoked
  • Loading branch information
nono committed Apr 19, 2017
1 parent e33543f commit ae6f8ee
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function cozyFetchWithAuth (cozy, fullpath, options, credentials) {
cozy.isV2(),
fetch(fullpath, options)
]).then(([isV2, res]) => {
if ((res.status !== 401 && res.status !== 400) || isV2 || !credentials) {
if ((res.status !== 400 && res.status !== 401) || isV2 || !credentials || options.dontRetry) {
return res
}
// we try to refresh the token only for OAuth, ie, the client defined
Expand All @@ -41,6 +41,7 @@ function cozyFetchWithAuth (cozy, fullpath, options, credentials) {
if (!client || !(token instanceof AccessToken)) {
return res
}
options.dontRetry = true
return retry(() => refreshToken(cozy, client, token), 3)()
.then((newToken) => cozy.saveCredentials(client, newToken))
.then((credentials) => cozyFetchWithAuth(cozy, fullpath, options, credentials))
Expand Down

0 comments on commit ae6f8ee

Please sign in to comment.