From a111c6170a1694bb365ed49ffc90442f8f8f6168 Mon Sep 17 00:00:00 2001 From: Bruno Michel Date: Mon, 4 Oct 2021 17:04:23 +0200 Subject: [PATCH] fix: Allow 401 errors for expired tokens The stack will change the http code used for expired tokens from 400 to 401. This change will allow cozy-client to try refreshing the token in such cases. See https://github.com/cozy/cozy-stack/pull/3173 --- packages/cozy-pouch-link/examples/periodic-sync/index.js | 2 +- packages/cozy-pouch-link/src/CozyPouchLink.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/cozy-pouch-link/examples/periodic-sync/index.js b/packages/cozy-pouch-link/examples/periodic-sync/index.js index c42ba7bd3b..ecfa6b5990 100755 --- a/packages/cozy-pouch-link/examples/periodic-sync/index.js +++ b/packages/cozy-pouch-link/examples/periodic-sync/index.js @@ -88,7 +88,7 @@ class App extends React.Component { replicationDelay: 2 * 1000, getReplicationURL: this.getReplicationURL, onError: err => { - if (err.error == 'code=400, message=Expired token') { + if (/Expired token/.test(err.error)) { console.log('You need to refresh the token') } this.setState({ error: err.error }) diff --git a/packages/cozy-pouch-link/src/CozyPouchLink.js b/packages/cozy-pouch-link/src/CozyPouchLink.js index 19344d6e5e..db60528de2 100644 --- a/packages/cozy-pouch-link/src/CozyPouchLink.js +++ b/packages/cozy-pouch-link/src/CozyPouchLink.js @@ -53,8 +53,9 @@ export const getReplicationURL = (uri, token, doctype) => { } const doNothing = () => {} +const expiredTokenError = /Expired token/ export const isExpiredTokenError = pouchError => { - return pouchError.error === 'code=400, message=Expired token' + return expiredTokenError.test(pouchError.error) } const normalizeAll = (docs, doctype) => {