Skip to content

Instantly share code, notes, and snippets.

@asvechkar
Last active March 3, 2018 14:18
Show Gist options
  • Save asvechkar/8a91006fb20cf16b5d4891f2f97e0efa to your computer and use it in GitHub Desktop.
Save asvechkar/8a91006fb20cf16b5d4891f2f97e0efa to your computer and use it in GitHub Desktop.
Vue interceptors
// 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