import axios from 'axios';

const instance = axios.create({
  baseURL: '/',
  // withCredentials: true,
});

instance.interceptors.request.use(config => {
  return config;
})

instance.interceptors.response.use(response => {
  if(process.env.NODE_ENV !== 'production') {
    console.log('response', response);
  }
  const { data: res = {} } = response;
  const { code } = res;
  if(code === 200 || code === 20000) return Promise.resolve(res.data);
  const error = new Error(res.msg || res.message || '请求异常');
  error.data = res;
  return Promise.reject(error);
})

export default instance;
