Remove error handler from direct axios calls, the interceptor will do the job

This commit is contained in:
Bubka 2020-01-26 21:57:53 +01:00
parent c6b7c4e495
commit 90bf333934
4 changed files with 34 additions and 38 deletions

15
resources/js/api.js vendored
View File

@ -32,14 +32,21 @@ Vue.axios.interceptors.request.use(function (request) {
Vue.axios.interceptors.response.use(response => response, error => { Vue.axios.interceptors.response.use(response => response, error => {
if ( error.response.status === 404 ) { // Return the error when it has been asked
if( error.config.hasOwnProperty('returnError') && error.config.returnError === true ) {
return Promise.reject(error);
}
if( error.response.status === 422 ) {
return Promise.reject(error);
}
// Otherwise we push to the error views
if ( error.response.status === 404 ) {
router.push({name: '404', params: { err : error.response }}) router.push({name: '404', params: { err : error.response }})
} }
else { else {
router.push({ name: 'genericError', params: { err: error.response } })
// router.push({ name: 'genericError', params: { err: error.response } });
return Promise.reject(error)
} }

View File

@ -159,21 +159,17 @@
} }
}, },
logout(evt) { async logout(evt) {
if(confirm(this.$t('auth.confirm.logout'))) { if(confirm(this.$t('auth.confirm.logout'))) {
this.axios.get('api/logout') await this.axios.get('api/logout')
.then(response => {
localStorage.removeItem('jwt');
localStorage.removeItem('user');
delete this.axios.defaults.headers.common['Authorization']; localStorage.removeItem('jwt');
localStorage.removeItem('user');
this.$router.go('/login'); delete this.axios.defaults.headers.common['Authorization'];
})
.catch(error => { this.$router.go('/login');
this.$router.push({ name: 'genericError', params: { err: error.response } });
});
} }
} }

View File

@ -71,18 +71,15 @@
} }
}, },
created: function() { async created() {
// we check if a user account already exists // we check if a user account already exists
this.axios.post('api/checkuser') const { data } = await this.axios.post('api/checkuser')
.then(response => {
if( response.data.userCount > 0) { if( data.userCount > 0) {
this.errorMessage = this.$t('errors.already_one_user_registered') + ' ' + this.$t('errors.cannot_register_more_user') this.errorMessage = this.$t('errors.already_one_user_registered') + ' ' + this.$t('errors.cannot_register_more_user')
this.$router.push({ name: 'flooded' }); this.$router.push({ name: 'flooded' });
} }
})
.catch(error => {
this.$router.push({ name: 'genericError', params: { err: error.response } });
});
}, },
methods : { methods : {

View File

@ -103,23 +103,19 @@
}, },
methods: { methods: {
getAccount () { async getAccount () {
this.axios.get('/api/twofaccounts/' + this.$route.params.twofaccountId) const { data } = await this.axios.get('/api/twofaccounts/' + this.$route.params.twofaccountId)
.then(response => {
this.form.fill(response.data)
this.twofaccountExists = true
// set account icon as temp icon this.form.fill(data)
this.tempIcon = this.form.icon this.twofaccountExists = true
})
.catch(error => {
this.$router.push({ name: 'genericError', params: { err: error.response } });
});
// set account icon as temp icon
this.tempIcon = this.form.icon
}, },
updateAccount() { async updateAccount() {
// Set new icon and delete old one // Set new icon and delete old one
if( this.tempIcon !== this.form.icon ) { if( this.tempIcon !== this.form.icon ) {