import axios, { InternalAxiosRequestConfig, AxiosResponse } from 'axios'


const service = axios.create({
    baseURL: '',
    timeout: 50000,
    headers: { 'Content-Type': 'application/json;charset=utf-8' }
})

service.interceptors.request.use((config: InternalAxiosRequestConfig) => {
    // if(token){
    // config.headers.Authorization = token
    // }
    return config
}, (error: any) => {
    return Promise.reject(error)
}
)

service.interceptors.response.use((response: AxiosResponse) => {
    const { code, msg } = response.data

    if (code == '00000') {
        return response.data
    }

    return Promise.reject(new Error(msg || 'Error'))
}, (error: any) => {
    if (error.response.data) {
        const { code, msg } = error.response.data
        if (code == '401') {

        }
    }
    return Promise.reject(error.message)
}
)

export default service