From ae6f8ee046c155a207d95f9d61df4a1b33588412 Mon Sep 17 00:00:00 2001 From: Bruno Michel Date: Wed, 19 Apr 2017 16:20:54 +0200 Subject: [PATCH] Break an infinite loop of retry/failure when fetch returns a 400 but client is not revoked --- src/fetch.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fetch.js b/src/fetch.js index c6d24d0c..0a4840c2 100644 --- a/src/fetch.js +++ b/src/fetch.js @@ -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 @@ -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))