Add response interceptor to axios to handle errors

This commit is contained in:
Bubka 2020-01-16 13:52:26 +01:00
parent d9b8419ac9
commit 2fc1ec4020

View File

@ -13,3 +13,19 @@ axios.interceptors.request.use(request => {
return request
})
// Response interceptor
axios.interceptors.response.use(response => response, error => {
const { status } = error.response
if (status >= 500) {
// do something ?
}
if (status === 404) {
router.push({name: '404', params: { err : error.response.data.error }})
}
return Promise.reject(error)
})