materio-d9/web/themes/custom/materiotheme/vuejs/api/ma-axios.js

49 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

import axios from 'axios'
// https://github.com/alvar0hurtad0/drupal-vuejs-todo/blob/master/frontend/src/api/axiosInterceptor.js
// console.log('drupalSettings', drupalSettings)
2021-09-21 11:05:29 +02:00
// axios.interceptors.response.use(
// response => {
// // console.log('ma-axios interceptor response', response)
// return Promise.resolve(response)
// // return response
// },
// error => {
// const { status } = error.response
// console.warn('error in ma-axios response interceptor, status:', status)
// if (status === 403) {
// window.location = '/'
// }
// return Promise.reject(error)
// }
// )
const MA = axios.create({
baseURL: window.location.origin + '/' + drupalSettings.path.pathPrefix,
withCredentials: true,
headers: {
'Content-Type': 'application/json'
2020-11-24 14:07:10 +01:00
// "X-CSRF-Token": "csrf_token"
}
})
MA.interceptors.response.use(
response => {
// console.log('ma-axios interceptor response', response)
return Promise.resolve(response)
// return response
},
error => {
const { status } = error.response
console.warn('error in ma-axios interceptor', status)
if (status === 403) {
window.location = '/'
}
return Promise.reject(error)
}
)
export default MA