diff --git a/front/src/components/auth/Signup.vue b/front/src/components/auth/Signup.vue index 13b723d201437933d9f6fd46bcaccfb2d316f5ed..749d2eb0254a5d55b163532afff252302b4d50e6 100644 --- a/front/src/components/auth/Signup.vue +++ b/front/src/components/auth/Signup.vue @@ -100,24 +100,9 @@ export default { username: this.username }}) }, error => { - self.errors = this.getErrors(error.response) + self.errors = error.backendErrors self.isLoading = false }) - }, - getErrors (response) { - let errors = [] - if (response.status !== 400) { - errors.push('An unknown error occured, ensure your are connected to the internet and your funkwhale instance is up and running') - return errors - } - for (var field in response.data) { - if (response.data.hasOwnProperty(field)) { - response.data[field].forEach(e => { - errors.push(e) - }) - } - } - return errors } }, computed: { diff --git a/front/src/main.js b/front/src/main.js index caf924188086270a8d0e598c9a5307d3fa57c1e2..f20af42bfa7ed7ab3850cc8ebf76d6e4ae0916e7 100644 --- a/front/src/main.js +++ b/front/src/main.js @@ -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) })