提交 67659a00 编写于 作者: 丁田秀

fix(locale): 删除request错误捕捉

上级 6f930077
...@@ -2,7 +2,7 @@ import type { Settings as LayoutSettings } from '@ant-design/pro-layout'; ...@@ -2,7 +2,7 @@ import type { Settings as LayoutSettings } from '@ant-design/pro-layout';
import { PageLoading } from '@ant-design/pro-layout'; import { PageLoading } from '@ant-design/pro-layout';
import { notification } from 'antd'; import { notification } from 'antd';
import type { RequestConfig, RunTimeLayoutConfig } from 'umi'; import type { RequestConfig, RunTimeLayoutConfig } from 'umi';
import { getIntl, getLocale, history, Link } from 'umi'; import { history, Link } from 'umi';
import RightContent from '@/components/RightContent'; import RightContent from '@/components/RightContent';
import Footer from '@/components/Footer'; import Footer from '@/components/Footer';
import type { ResponseError } from 'umi-request'; import type { ResponseError } from 'umi-request';
...@@ -51,7 +51,6 @@ export async function getInitialState(): Promise<{ ...@@ -51,7 +51,6 @@ export async function getInitialState(): Promise<{
/** /**
* 异常处理程序 * 异常处理程序
const codeMessage = {
200: '服务器成功返回请求的数据。', 200: '服务器成功返回请求的数据。',
201: '新建或修改数据成功。', 201: '新建或修改数据成功。',
202: '一个请求已经进入后台排队(异步任务)。', 202: '一个请求已经进入后台排队(异步任务)。',
...@@ -68,25 +67,30 @@ export async function getInitialState(): Promise<{ ...@@ -68,25 +67,30 @@ export async function getInitialState(): Promise<{
502: '网关错误。', 502: '网关错误。',
503: '服务不可用,服务器暂时过载或维护。', 503: '服务不可用,服务器暂时过载或维护。',
504: '网关超时。', 504: '网关超时。',
}; //-----English
200: The server successfully returned the requested data. ',
201: New or modified data is successful. ',
202: A request has entered the background queue (asynchronous task). ',
204: Data deleted successfully. ',
400: 'There was an error in the request sent, and the server did not create or modify data. ',
401: The user does not have permission (token, username, password error). ',
403: The user is authorized, but access is forbidden. ',
404: The request sent was for a record that did not exist. ',
405: The request method is not allowed. ',
406: The requested format is not available. ',
410':
'The requested resource is permanently deleted and will no longer be available. ',
422: When creating an object, a validation error occurred. ',
500: An error occurred on the server, please check the server. ',
502: Gateway error. ',
503: The service is unavailable. ',
504: The gateway timed out. ',
* @see https://beta-pro.ant.design/docs/request-cn * @see https://beta-pro.ant.design/docs/request-cn
*/ */
export const request: RequestConfig = { export const request: RequestConfig = {
errorHandler: (error: ResponseError) => { errorHandler: (error: ResponseError) => {
const { messages } = getIntl(getLocale());
const { response } = error; const { response } = error;
if (response && response.status) {
const { status, statusText, url } = response;
const requestErrorMessage = messages['app.request.error'];
const errorMessage = `${requestErrorMessage} ${status}: ${url}`;
const errorDescription = messages[`app.request.${status}`] || statusText;
notification.error({
message: errorMessage,
description: errorDescription,
});
}
if (!response) { if (!response) {
notification.error({ notification.error({
description: '您的网络发生异常,无法连接服务器', description: '您的网络发生异常,无法连接服务器',
......
...@@ -3,7 +3,6 @@ import globalHeader from './en-US/globalHeader'; ...@@ -3,7 +3,6 @@ import globalHeader from './en-US/globalHeader';
import menu from './en-US/menu'; import menu from './en-US/menu';
import pages from './en-US/pages'; import pages from './en-US/pages';
import pwa from './en-US/pwa'; import pwa from './en-US/pwa';
import request from './en-US/request';
import settingDrawer from './en-US/settingDrawer'; import settingDrawer from './en-US/settingDrawer';
import settings from './en-US/settings'; import settings from './en-US/settings';
...@@ -23,5 +22,4 @@ export default { ...@@ -23,5 +22,4 @@ export default {
...pwa, ...pwa,
...component, ...component,
...pages, ...pages,
...request,
}; };
export default {
'app.request.error': 'Request error',
'app.request.200': 'The server successfully returned the requested data. ',
'app.request.201': 'New or modified data is successful. ',
'app.request.202': 'A request has entered the background queue (asynchronous task). ',
'app.request.204': 'Data deleted successfully. ',
'app.request.400':
'There was an error in the request sent, and the server did not create or modify data. ',
'app.request.401': 'The user does not have permission (token, username, password error). ',
'app.request.403': 'The user is authorized, but access is forbidden. ',
'app.request.404': 'The request sent was for a record that did not exist. ',
'app.request.405': 'The request method is not allowed. ',
'app.request.406': 'The requested format is not available. ',
'app.request.410':
'The requested resource is permanently deleted and will no longer be available. ',
'app.request.422': 'When creating an object, a validation error occurred. ',
'app.request.500': 'An error occurred on the server, please check the server. ',
'app.request.502': 'Gateway error. ',
'app.request.503': 'The service is unavailable. ',
'app.request.504': 'The gateway timed out. ',
};
...@@ -2,7 +2,6 @@ import component from './zh-CN/component'; ...@@ -2,7 +2,6 @@ import component from './zh-CN/component';
import globalHeader from './zh-CN/globalHeader'; import globalHeader from './zh-CN/globalHeader';
import menu from './zh-CN/menu'; import menu from './zh-CN/menu';
import pwa from './zh-CN/pwa'; import pwa from './zh-CN/pwa';
import request from './zh-CN/request';
import settingDrawer from './zh-CN/settingDrawer'; import settingDrawer from './zh-CN/settingDrawer';
import settings from './zh-CN/settings'; import settings from './zh-CN/settings';
import pages from './zh-CN/pages'; import pages from './zh-CN/pages';
...@@ -23,5 +22,4 @@ export default { ...@@ -23,5 +22,4 @@ export default {
...settings, ...settings,
...pwa, ...pwa,
...component, ...component,
...request,
}; };
export default {
'app.request.error': '请求错误',
'app.request.200': '服务器成功返回请求的数据。',
'app.request.201': '新建或修改数据成功。',
'app.request.202': '一个请求已经进入后台排队(异步任务)。',
'app.request.204': '删除数据成功。',
'app.request.400': '发出的请求有错误,服务器没有进行新建或修改数据的操作。',
'app.request.401': '用户没有权限(令牌、用户名、密码错误)。',
'app.request.403': '用户得到授权,但是访问是被禁止的。',
'app.request.404': '发出的请求针对的是不存在的记录,服务器没有进行操作。',
'app.request.405': '请求方法不被允许。',
'app.request.406': '请求的格式不可得。',
'app.request.410': '请求的资源被永久删除,且不会再得到的。',
'app.request.422': '当创建一个对象时,发生一个验证错误。',
'app.request.500': '服务器发生错误,请检查服务器。',
'app.request.502': '网关错误。',
'app.request.503': '服务不可用,服务器暂时过载或维护。',
'app.request.504': '网关超时。',
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册