import axios from 'axios';
import { show_message } from './tdesign_tool';
const instance = axios.create({
  timeout: 60000,
  withCredentials: false,
});
// 请求头
instance.interceptors.request.use((config: any) => {
  return config;
});

instance.interceptors.response.use(
  (response) => {
    const { data } = response;
    if (data) {
      return data;
    } else {
      show_message(data.msg || '请求错误', 'error');
      return Promise.reject(data.msg);
    }
  },
  (err) => {
    if ('response' in err) {
      const { message: msg } = err.response.data;
      show_message(msg || '请求错误', 'error');
      return err.response;
    }
  }
);

export default instance;
