Browse Source

fix: 抽离接口异常code

main
xuziqiang 5 months ago
parent
commit
46398fda22
  1. 10
      hx-ai-intelligent/src/enum/http-enum.ts
  2. 12
      lib/util/http/axios.ts

10
hx-ai-intelligent/src/enum/http-enum.ts

@ -1,3 +1,5 @@
import { routerConfig } from '/nerv-lib/saas/config/router.config';
export enum ResultEnum { export enum ResultEnum {
SUCCESS = 0, SUCCESS = 0,
ERROR = 1, ERROR = 1,
@ -20,3 +22,11 @@ export enum ContentTypeEnum {
// form-data upload // form-data upload
FORM_DATA = 'multipart/form-data;charset=UTF-8', FORM_DATA = 'multipart/form-data;charset=UTF-8',
} }
export const errCodeMap = new Map<number, any>([
[13, ''],
[1, ''],
[11, ''],
[3005, ''],
[10086, () => routerConfig.logout()],
]);

12
lib/util/http/axios.ts

@ -4,7 +4,7 @@ import type { Result } from './axios.d';
import { NsMessage } from '/nerv-lib/component/message'; import { NsMessage } from '/nerv-lib/component/message';
import { routerConfig } from '/nerv-base/config/router.config'; import { routerConfig } from '/nerv-base/config/router.config';
import { Cookies } from '/nerv-lib/util/cookie'; import { Cookies } from '/nerv-lib/util/cookie';
import { RequestEnum } from '/@/enum/http-enum.ts'; import { RequestEnum, errCodeMap } from '/@/enum/http-enum.ts';
export class NSAxios { export class NSAxios {
private instance: AxiosInstance; private instance: AxiosInstance;
@ -75,14 +75,6 @@ export class NSAxios {
return config; return config;
}, undefined); }, undefined);
const errCodeMap = new Map<number, any>([
[13, ''],
[1, ''],
[11, ''],
[3005, ''],
[10086, () => routerConfig.logout()],
]);
// type closeType = (() => void) | undefined; // type closeType = (() => void) | undefined;
this.instance.interceptors.response.use( this.instance.interceptors.response.use(
(res: AxiosResponse) => { (res: AxiosResponse) => {
@ -90,8 +82,6 @@ export class NSAxios {
const code = res?.data?.retcode; const code = res?.data?.retcode;
const msg = res?.data?.msg; const msg = res?.data?.msg;
if (errCodeMap.has(code)) { if (errCodeMap.has(code)) {
console.log(errCodeMap.get(code));
NsMessage.error({ NsMessage.error({
content: msg, content: msg,
key: this.errorMsgKey, key: this.errorMsgKey,

Loading…
Cancel
Save