Skip to content

Instantly share code, notes, and snippets.

@eichgi
Created May 15, 2020 00:21
Show Gist options
  • Save eichgi/3baee29173b953939fb6aa16f1fe5e8c to your computer and use it in GitHub Desktop.
Save eichgi/3baee29173b953939fb6aa16f1fe5e8c to your computer and use it in GitHub Desktop.
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