Skip to content

Commit ae6f8ee

Browse files
committed
Break an infinite loop of retry/failure when fetch returns a 400 but client is not revoked
1 parent e33543f commit ae6f8ee

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/fetch.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function cozyFetchWithAuth (cozy, fullpath, options, credentials) {
3232
cozy.isV2(),
3333
fetch(fullpath, options)
3434
]).then(([isV2, res]) => {
35-
if ((res.status !== 401 && res.status !== 400) || isV2 || !credentials) {
35+
if ((res.status !== 400 && res.status !== 401) || isV2 || !credentials || options.dontRetry) {
3636
return res
3737
}
3838
// we try to refresh the token only for OAuth, ie, the client defined
@@ -41,6 +41,7 @@ function cozyFetchWithAuth (cozy, fullpath, options, credentials) {
4141
if (!client || !(token instanceof AccessToken)) {
4242
return res
4343
}
44+
options.dontRetry = true
4445
return retry(() => refreshToken(cozy, client, token), 3)()
4546
.then((newToken) => cozy.saveCredentials(client, newToken))
4647
.then((credentials) => cozyFetchWithAuth(cozy, fullpath, options, credentials))

0 commit comments

Comments
 (0)