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 => {
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 }})
}
else {
// router.push({ name: 'genericError', params: { err: error.response } });
return Promise.reject(error)
router.push({ name: 'genericError', params: { err: error.response } })
}

View File

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

View File

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

View File

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