Files
saladeaula.digital/dashboard_js/app/axios.js
2025-02-22 11:57:18 -03:00

26 lines
628 B
JavaScript

import axios from 'axios'
const instance = axios.create({
baseURL: import.meta.env.VITE_API_URL,
})
instance.interceptors.response.use(
// Any status code that lie within the range of 2xx cause this function to trigger
function (response) {
return response
},
// Any status codes that falls outside the range of 2xx cause this function to trigger
function ({ response }) {
const error = new Error(response.data?.message)
error.code = response.data?.__type
error.name = response.data?.__type
error.statusCode = response.status
return Promise.reject(error)
},
)
export default instance