736d7118b0
Still work to be done but a good start in standardisation.
21 lines
No EOL
770 B
JavaScript
21 lines
No EOL
770 B
JavaScript
import axios from "axios"
|
|
|
|
function instance() {
|
|
let axiosInstance = axios.create({
|
|
headers: {
|
|
'X-CSRF-TOKEN': document.querySelector('meta[name=token]').getAttribute('content'),
|
|
'baseURL': window.baseUrl('')
|
|
}
|
|
});
|
|
axiosInstance.interceptors.request.use(resp => {
|
|
return resp;
|
|
}, err => {
|
|
if (typeof err.response === "undefined" || typeof err.response.data === "undefined") return Promise.reject(err);
|
|
if (typeof err.response.data.error !== "undefined") window.$events.emit('error', err.response.data.error);
|
|
if (typeof err.response.data.message !== "undefined") window.$events.emit('error', err.response.data.message);
|
|
});
|
|
return axiosInstance;
|
|
}
|
|
|
|
|
|
export default instance; |