
import axios from 'axios'

const service = axios.create({
  baseURL: import.meta.env.VITE_API_BASE_URL,
  timeout: 200000,
  withCredentials: false
})

service.interceptors.request.use(
  config => {


    return config
  },
  error => {
    return Promise.reject(error)
  }
)

service.interceptors.response.use(

  response => {

    const res = response
    const config = response.config
    if (res.status >=400) {
    
      return Promise.reject(res.msg || 'Error')
    } else {

      const { isTransformResponse } = config
      if (isTransformResponse) {
        return res
      }
      return res.data
    }
  },
  error => {
    return Promise.reject(error)
  }
)

export default service