Inviter
This commit is contained in:
@@ -14,9 +14,13 @@ export interface AppResp<T = any> {
|
||||
const successLabel = 'color:white;background-color:green;padding: 1px 2px';
|
||||
const failureLabel = 'color:white;background-color:red;padding: 1px 2px';
|
||||
const originLabel = 'color:unset;background-color:unset;padding:unset';
|
||||
const errorMap = {
|
||||
404: 'common.404',
|
||||
403: 'common.403',
|
||||
};
|
||||
|
||||
// const baseURL = 'https://server.fiv.tacever.org/v1';
|
||||
const baseURL = '//yapi.faronear.org/mock/20/v1';
|
||||
const baseURL = 'https://server.fiv.tacever.org/v1';
|
||||
// const baseURL = '//yapi.faronear.org/mock/20/v1';
|
||||
const instance = axios.create({
|
||||
baseURL,
|
||||
});
|
||||
@@ -55,9 +59,6 @@ async function filter<T>(
|
||||
}
|
||||
const { status, data } = await (instance[method] as (...args: any[]) => Promise<AxiosResponse<AppResp>>)(...args);
|
||||
replaceId(data);
|
||||
if (data && data.code === 401) {
|
||||
dispatch({ type: 'user/logout' });
|
||||
}
|
||||
ret = {
|
||||
ok: status >= 200 && status < 300 && data && data.code === 0,
|
||||
code: data && data.code,
|
||||
@@ -65,10 +66,19 @@ async function filter<T>(
|
||||
data: data && data.data,
|
||||
};
|
||||
} catch (e) {
|
||||
let code = 404;
|
||||
let msg = 'network.error';
|
||||
if (e.response) {
|
||||
code = e.response.status;
|
||||
msg = (errorMap as any)[code] || 'network.error';
|
||||
if (code === 403 || code === 401) {
|
||||
dispatch({ type: 'user/logout' });
|
||||
}
|
||||
}
|
||||
ret = {
|
||||
ok: false,
|
||||
msg: formatMessage({ id: 'network.error' }),
|
||||
code: 404,
|
||||
msg: formatMessage({ id: msg }),
|
||||
code,
|
||||
};
|
||||
}
|
||||
if (isDev) {
|
||||
|
||||
Reference in New Issue
Block a user