Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafabarbosa/de3b5c008d649d95ca37908dcc71777d to your computer and use it in GitHub Desktop.
Save rafabarbosa/de3b5c008d649d95ca37908dcc71777d to your computer and use it in GitHub Desktop.
Axios 401 response interceptor.
// Add a 401 response interceptor
window.axios.interceptors.response.use(function (response) {
return response;
}, function (error) {
if (401 === error.response.status) {
swal({
title: "Session Expired",
text: "Your session has expired. Would you like to be redirected to the login page?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
closeOnConfirm: false
}, function(){
window.location = '/login';
});
} else {
return Promise.reject(error);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment