Skip to content

Commit

Permalink
Merge pull request #136 from nono/break-infinite-loop
Browse files Browse the repository at this point in the history
Break an infinite loop of retry/failure
  • Loading branch information
kosssi authored Apr 21, 2017
2 parents 967a8af + ae6f8ee commit 53b8e31
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 53b8e31

Please sign in to comment.