ma-axios.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import axios from 'axios'
  2. // https://github.com/alvar0hurtad0/drupal-vuejs-todo/blob/master/frontend/src/api/axiosInterceptor.js
  3. // console.log('drupalSettings', drupalSettings)
  4. // axios.interceptors.response.use(
  5. // response => {
  6. // // console.log('ma-axios interceptor response', response)
  7. // return Promise.resolve(response)
  8. // // return response
  9. // },
  10. // error => {
  11. // const { status } = error.response
  12. // console.warn('error in ma-axios response interceptor, status:', status)
  13. // if (status === 403) {
  14. // window.location = '/'
  15. // }
  16. // return Promise.reject(error)
  17. // }
  18. // )
  19. const MA = axios.create({
  20. baseURL: window.location.origin + '/' + drupalSettings.path.pathPrefix,
  21. withCredentials: true,
  22. headers: {
  23. 'Content-Type': 'application/json'
  24. // "X-CSRF-Token": "csrf_token"
  25. }
  26. })
  27. MA.interceptors.response.use(
  28. response => {
  29. // console.log('ma-axios interceptor response', response)
  30. return Promise.resolve(response)
  31. // return response
  32. },
  33. error => {
  34. const { status } = error.response
  35. console.warn('error in ma-axios interceptor', status)
  36. if (status === 403) {
  37. window.location = '/'
  38. }
  39. return Promise.reject(error)
  40. }
  41. )
  42. export default MA