Last active
March 3, 2018 14:18
-
-
Save asvechkar/8a91006fb20cf16b5d4891f2f97e0efa to your computer and use it in GitHub Desktop.
Vue interceptors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// HTTP service http.js | |
axios.interceptors.response.use(response => { | |
return response | |
}, error => { | |
if (error.response.status === 401) { | |
bus.$emit('errors:401') | |
return Promise.reject() | |
} else { | |
bus.$emit('error', error.response.data) | |
return Promise.reject() | |
} | |
}) | |
// root component App.js | |
bus.$on('error:401', () => { | |
this.$router.push('/login') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment