Created
May 15, 2020 00:21
-
-
Save eichgi/3baee29173b953939fb6aa16f1fe5e8c to your computer and use it in GitHub Desktop.
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
import axios from 'axios'; | |
import store from './../store/index'; | |
import Swal from 'sweetalert2'; | |
const http = axios.create({ | |
baseURL: process.env.VUE_APP_API_URL, | |
headers: { | |
Authorization: 'Bearer ' + store.getters.token, | |
}, | |
}); | |
http.interceptors.response.use( | |
response => response, | |
error => { | |
if (error.response.status === 401) { | |
Swal.fire('Tu sesión ha expirado', 'Por favor vuelve a iniciar sesión', 'warning'); | |
store.dispatch('logout'); | |
} | |
if (error.response.status === 503) { | |
Swal.fire('App en mantenimiento', 'Por favor vuelve en un rato', 'warning'); | |
store.dispatch('logout'); | |
} | |
}); | |
export {http}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment