hi!
Migrations says: "Default error interceptor removed".
Is there any example with best practice how to handle exception now?
I saw documentation:
export default function ({ $axios, redirect }) {
$axios.onRequest(config => {
console.log('Making request to ' + config.url)
})
$axios.onError(error => {
const code = parseInt(error.response && error.response.status)
if (code === 400) {
redirect('/400')
}
})
}
But I am not sure how to pass error to the nuxt page to print the stack trace etc.
Thanks!
consol.error should be enough there. export default function ({ $axios, redirect, app, store }) {
$axios.onError(error => {
// with @nuxtjs/toast
app.$toast.error('Error while making request: ' + error.response.message)
// with a custom store action
store.dispatch('error', error)
})
}
````
- To handle error while making requests (For example inside a page) without a global handler, you can even forget about `onError` interceptor. I prefer using `.catch` instead of `try/catch`:
```js
// ...inside a method
this.$axios.$get('/api/foo/bar').catch(e => { ... })
Most helpful comment
consol.errorshould be enough there.