Skip to content

Commit

Permalink
fix: Don't throw USER_ACTION_NEEDED_OAUTH_OUTDATED on Invalid credent…
Browse files Browse the repository at this point in the history
…ials
  • Loading branch information
cedricmessiant committed Mar 15, 2019
1 parent dc34710 commit 3d98027
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,29 +118,34 @@ async function start(fields, doRetry = true) {
) {
log('info', 'insufficient scopes')
throw errors.USER_ACTION_NEEDED_OAUTH_OUTDATED
} else if (!fields.refresh_token) {
log('info', 'no refresh token found')
throw errors.USER_ACTION_NEEDED_OAUTH_OUTDATED
} else if (doRetry) {
log('info', 'asking refresh from the stack')
let body
try {
body = await cozyClient.fetchJSON(
'POST',
`/accounts/google/${accountId}/refresh`
)
} catch (err) {
log('info', `Error during refresh ${err.message}`)
} else if (
err.message === 'No refresh token is set.' ||
err.message === 'Invalid Credentials'
) {
if (!fields.refresh_token) {
log('info', 'no refresh token found')
throw errors.USER_ACTION_NEEDED_OAUTH_OUTDATED
}
} else if (doRetry) {
log('info', 'asking refresh from the stack')
let body
try {
body = await cozyClient.fetchJSON(
'POST',
`/accounts/google/${accountId}/refresh`
)
} catch (err) {
log('info', `Error during refresh ${err.message}`)
throw errors.USER_ACTION_NEEDED_OAUTH_OUTDATED
}

log('info', 'refresh response')
log('info', JSON.stringify(body))
fields.access_token = body.attributes.oauth.access_token
return start(fields, false)
log('info', 'refresh response')
log('info', JSON.stringify(body))
fields.access_token = body.attributes.oauth.access_token
return start(fields, false)
}
} else {
log('info', `Error during authentication ${err.message}`)
throw errors.USER_ACTION_NEEDED_OAUTH_OUTDATED
log('error', `Error during authentication ${err.message}`)
throw errors.VENDOR_DOWN
}
} else {
log('error', 'caught an unexpected error')
Expand Down

0 comments on commit 3d98027

Please sign in to comment.