Last active
August 18, 2020 19:13
-
-
Save danielstgt/cfe1094dd58cbae522c30cdc4f656ef6 to your computer and use it in GitHub Desktop.
axios interceptor for expired sessions with SweetAlert
This file contains 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
axios.interceptors.response.use(response => { | |
return response; | |
}, error => { | |
if (error.response.status === 401) { | |
Swal.fire({ | |
title: 'Session expired', | |
text: 'Please sign in again!', | |
type: 'error', | |
}).then(result => { | |
if (result.value) { | |
location.reload(); | |
} | |
}); | |
} | |
return Promise.reject(error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment