2019-05-31 15:01:54 +02:00
|
|
|
import axios from 'axios'
|
|
|
|
|
|
|
|
// https://github.com/alvar0hurtad0/drupal-vuejs-todo/blob/master/frontend/src/api/axiosInterceptor.js
|
|
|
|
|
2021-03-31 18:42:05 +02:00
|
|
|
// console.log('drupalSettings', drupalSettings)
|
2019-05-31 15:01:54 +02:00
|
|
|
|
2021-09-16 21:40:18 +02:00
|
|
|
const MA = axios.create({
|
2019-05-31 23:05:37 +02:00
|
|
|
baseURL: window.location.origin + '/' + drupalSettings.path.pathPrefix,
|
2019-05-31 15:01:54 +02:00
|
|
|
withCredentials: true,
|
|
|
|
headers: {
|
2021-03-31 18:42:05 +02:00
|
|
|
'Content-Type': 'application/json'
|
2020-11-24 14:07:10 +01:00
|
|
|
// "X-CSRF-Token": "csrf_token"
|
2019-05-31 15:01:54 +02:00
|
|
|
}
|
|
|
|
})
|
2021-09-16 21:40:18 +02:00
|
|
|
|
|
|
|
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
|