import axios from "axios";

// 服务端请求

const server = axios.create({
  baseURL: import.meta.env.BASE_SERVER,
  timeout: 10000,
});

server.interceptors.request.use(config => {
  // 暂无需要处理的内容
  return config;
});

server.interceptors.response.use(response => {
  const { data, status } = response;
  if (data?.code === 1000 || data?.code === 200) {
    return data.data;
  }

  if (data?.message || data?.msg) {
    throw new Error(data?.message || data?.msg);
  }

  throw new Error(`网络异常 - ${status}`)
});

export const request = server;
