Skip to content

Commit

Permalink
feat: traite les erreurs 40x d'API
Browse files Browse the repository at this point in the history
Signed-off-by: Maud Royer <hello@maudroyer.fr>
  • Loading branch information
jillro committed Jun 24, 2024
1 parent f45b8ba commit 0b95524
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,31 @@ router.beforeEach(async (to) => {
const { useRecordStore } = await import('@/stores/record.js')
const recordStore = useRecordStore()
// Preload stores for checking permissions
if (to.params.recordId) {
await recordStore.ready(to.params.recordId) // will load also the operator
} else if (to.params.numeroBio) {
recordStore.$reset()
const { useOperatorStore } = await import('@/stores/operator.js')
const operatorStore = useOperatorStore()
await operatorStore.ready(to.params.numeroBio)
try {
if (to.params.recordId) {
await recordStore.ready(to.params.recordId) // will load also the operator
} else if (to.params.numeroBio) {
recordStore.$reset()
const { useOperatorStore } = await import('@/stores/operator.js')
const operatorStore = useOperatorStore()
await operatorStore.ready(to.params.numeroBio)
}
} catch (error) {
if (error?.response?.status === 404) {
toast.error('L\'exploitation demandée n\'existe pas.')
return false
}

if (error?.response?.status === 403) {
toast.error('Vous n\'avez pas les droits pour accéder à cette page.')
return { path: userStore.startPage, replace: true }
}

if (error?.response?.status === 401) {
return { path: '/login', replace: true }
}

throw error
}

if (to.path === '/logout') {
Expand Down

0 comments on commit 0b95524

Please sign in to comment.