ma-axios.js 695 B

123456789101112131415161718192021222324252627282930313233
  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}/api`,
  6. withCredentials: true,
  7. headers: {
  8. Accept: 'application/json',
  9. 'Content-Type': 'application/json'
  10. }
  11. })
  12. MA.interceptors.response.use(
  13. response => {
  14. return Promise.resolve(response)
  15. },
  16. error => {
  17. const { status } = error.response
  18. console.warn('error in ma-axios interceptor', status)
  19. // if (status === 403) {
  20. // window.location = '/'
  21. // }
  22. return Promise.reject(error)
  23. }
  24. )
  25. export default MA