import Axios from "./axios";

const api = new Axios({ baseURL: process.env.VUE_APP_API });

api.instance.interceptors.request.use(
  config => config,
  err => Promise.reject(err)
);

api.instance.interceptors.response.use(
  res => {
    console.log(res.config.url, "------>", res.data);
    if (res.data.code !== 200) {
      return Promise.reject(
        res.data.msg || res.data.message || "未知错误，请稍后再试"
      );
    }
    return res.data;
  },
  err => Promise.reject(err)
);

export default api;
