diff --git a/src/fetch.js b/src/fetch.js index 4e6b6e0..2a93c90 100644 --- a/src/fetch.js +++ b/src/fetch.js @@ -184,7 +184,7 @@ FetchError.isInvalidToken = function(err) { // XXX We can't use err instanceof FetchError because of the caveats of babel return ( err.name === 'FetchError' && - err.status === 400 && + (err.status === 400 || err.status === 401) && err.reason && (err.reason.error === 'Invalid JWT token' || err.reason.error === 'Expired token') diff --git a/src/offline.js b/src/offline.js index d421c03..35c56ac 100644 --- a/src/offline.js +++ b/src/offline.js @@ -181,7 +181,7 @@ export function replicateFromCozy(cozy, doctype, options = {}) { options.onComplete && options.onComplete(info) }) .on('error', err => { - if (err.error === 'code=400, message=Expired token') { + if (/Expired token/.test(err.error)) { cozy.authorize().then(({ client, token }) => { refreshToken(cozy, client, token) .then(newToken => cozy.saveCredentials(client, newToken))