add axios
This commit is contained in:
@@ -1,5 +1,25 @@
|
||||
import axios from 'axios'
|
||||
|
||||
export default axios.create({
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user