Skip to content

Commit

Permalink
fix: Allow 401 errors for expired tokens
Browse files Browse the repository at this point in the history
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 cozy/cozy-stack#3173
  • Loading branch information
nono committed Oct 4, 2021
1 parent 927e18b commit a111c61
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/cozy-pouch-link/examples/periodic-sync/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
3 changes: 2 additions & 1 deletion packages/cozy-pouch-link/src/CozyPouchLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit a111c61

Please sign in to comment.