mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-11-08 01:14:29 +01:00
Add response interceptor to axios to handle errors
This commit is contained in:
parent
d9b8419ac9
commit
2fc1ec4020
16
resources/js/packages/axios.js
vendored
16
resources/js/packages/axios.js
vendored
@ -12,4 +12,20 @@ axios.interceptors.request.use(request => {
|
||||
request.headers.common['Content-Type'] = 'application/json'
|
||||
|
||||
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)
|
||||
})
|
Loading…
Reference in New Issue
Block a user