import axios from "axios"

import {attachAccessToken,authRequestError} from '@/utils/intercaptors/request/auth'
import { handlerefresherror } from "@/utils/intercaptors/response/refresh"

const request = axios.create({
    baseURL:'http://localhost:5292',
    timeout:10000,
    // ✅ 只把 status >= 500 视为错误，401/402/403 等都当作正常返回
  validateStatus: function (status) {
    return status < 500 // 500以上才视为 error，其他都进 then
  }
})

request.interceptors.request.use(attachAccessToken,authRequestError)

request.interceptors.response.use(
    handlerefresherror,
    err => err
)

request.interceptors.response.use(res=>{
    return res.data
},err => err
)

export default request