app.ts 966 字节
Newer Older
R
Rongfeng Fu 已提交
1
import { getLocale } from 'umi';
R
Rongfeng Fu 已提交
2 3
import type { RequestConfig } from 'umi';

R
Rongfeng Fu 已提交
4
const locale = getLocale() || 'zh-CN';
R
Rongfeng Fu 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
export const request: RequestConfig = {
  errorConfig: {
    adaptor: (resData) => {
      return {
        ...resData,
        success: resData.success,
        showType: 0,
      };
    },
  },
  requestInterceptors: [
    (url, options) => {
      return {
        url: url,
        options: {
          ...options,
          timeout: 180000,
          errorHandler: (e) => {
            console.log('---------------------------------------------');
            console.log('error.name:', e.name);
            console.log('error.response:', e.response);
            console.log('error.request:', e.request);
            console.log('error.type:', e.type);
            console.log('=============================================');
            throw e;
          },
        },
      };
    },
  ],
R
Rongfeng Fu 已提交
35 36 37
  headers: {
    'Accept-Language': locale,
  },
R
Rongfeng Fu 已提交
38
};