ma-axios.js 802 B

1234567891011121314151617181920212223242526272829303132
  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. const MA = axios.create({
  5. baseURL: window.location.origin + '/' + drupalSettings.path.pathPrefix,
  6. withCredentials: true,
  7. headers: {
  8. 'Content-Type': 'application/json'
  9. // "X-CSRF-Token": "csrf_token"
  10. }
  11. })
  12. MA.interceptors.response.use(
  13. response => {
  14. // console.log('ma-axios interceptor response', response)
  15. return Promise.resolve(response)
  16. // return response
  17. },
  18. error => {
  19. const { status } = error.response
  20. console.warn('error in ma-axios interceptor', status)
  21. if (status === 403) {
  22. window.location = '/'
  23. }
  24. return Promise.reject(error)
  25. }
  26. )
  27. export default MA