mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 23:39:16 +02:00
Moved backend error handling in axios
This commit is contained in:
parent
f9786d4b45
commit
2c79418d81
2 changed files with 18 additions and 16 deletions
|
@ -47,11 +47,28 @@ axios.interceptors.request.use(function (config) {
|
|||
axios.interceptors.response.use(function (response) {
|
||||
return response
|
||||
}, function (error) {
|
||||
error.backendErrors = []
|
||||
if (error.response.status === 401) {
|
||||
store.commit('auth/authenticated', false)
|
||||
logger.default.warn('Received 401 response from API, redirecting to login form')
|
||||
router.push({name: 'login', query: {next: router.currentRoute.fullPath}})
|
||||
}
|
||||
if (error.response.status === 404) {
|
||||
error.backendErrors.push('Resource not found')
|
||||
} else if (error.response.status === 500) {
|
||||
error.backendErrors.push('A server error occured')
|
||||
} else if (error.response.data) {
|
||||
for (var field in error.response.data) {
|
||||
if (error.response.data.hasOwnProperty(field)) {
|
||||
error.response.data[field].forEach(e => {
|
||||
error.backendErrors.push(e)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
if (error.backendErrors.length === 0) {
|
||||
error.backendErrors.push('An unknown error occured, ensure your are connected to the internet and your funkwhale instance is up and running')
|
||||
}
|
||||
// Do something with response error
|
||||
return Promise.reject(error)
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue