Skip to content

Commit

Permalink
feat: déconnecte seulement en présence du code erreur EXPIRED_CREDENT…
Browse files Browse the repository at this point in the history
…IALS
  • Loading branch information
thom4parisot committed Apr 8, 2024
1 parent 2d3314a commit ea94b71
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ function handlerAPIErrors(error) {
return true
}

// Token has expired: we disconnect and force render the current page to trigger the login mechanism
if (error.name === "AxiosError" && error.response?.status === 401) {
// Token has expired, as stated by the API error code
// We disconnect and force render the current page to trigger the login mechanism
if (error?.response?.data?.code === 'EXPIRED_CREDENTIALS') {
const { path, params } = router.currentRoute.value

userStore.logout()
Expand Down Expand Up @@ -137,7 +138,9 @@ router.onError((error, to) => {
return
}

toast.error('Une erreur est survenue. La page n\'a pas pu être chargée.')
// try to prefetch errors from response
const { message = 'Une erreur est survenue. La page n\'a pas pu être chargée.' } = error?.response?.data ?? {}
toast.error(message)
console.error(error)
throw error
})
Expand Down

0 comments on commit ea94b71

Please sign in to comment.