Improved error handling

This commit is contained in:
Eliot Berriot 2018-06-21 19:22:03 +02:00
parent bf8b143700
commit e3e0a2eaf4
No known key found for this signature in database
GPG Key ID: DD6965E2476E5C27
1 changed files with 9 additions and 5 deletions

View File

@ -86,6 +86,9 @@ axios.interceptors.response.use(function (response) {
} else if (error.response.status === 500) { } else if (error.response.status === 500) {
error.backendErrors.push('A server error occured') error.backendErrors.push('A server error occured')
} else if (error.response.data) { } else if (error.response.data) {
if (error.response.data.detail) {
error.backendErrors.push(error.response.data.detail)
} else {
for (var field in error.response.data) { for (var field in error.response.data) {
if (error.response.data.hasOwnProperty(field)) { if (error.response.data.hasOwnProperty(field)) {
error.response.data[field].forEach(e => { error.response.data[field].forEach(e => {
@ -94,6 +97,7 @@ axios.interceptors.response.use(function (response) {
} }
} }
} }
}
if (error.backendErrors.length === 0) { if (error.backendErrors.length === 0) {
error.backendErrors.push(i18next.t('An unknown error occured, ensure your are connected to the internet and your funkwhale instance is up and running')) error.backendErrors.push(i18next.t('An unknown error occured, ensure your are connected to the internet and your funkwhale instance is up and running'))
} }