diff --git a/back/loaders/express.ts b/back/loaders/express.ts index 41359f17..fe17e84c 100644 --- a/back/loaders/express.ts +++ b/back/loaders/express.ts @@ -159,8 +159,8 @@ export default ({ app }: { app: Application }) => { .status(500) .send({ code: 400, - message: `${err.name} ${err.message}`, - validation: err.errors, + message: `${err.message}`, + errors: err.errors, }) .end(); } diff --git a/src/locales/en-US.json b/src/locales/en-US.json index 19b7c78e..790e8596 100644 --- a/src/locales/en-US.json +++ b/src/locales/en-US.json @@ -393,7 +393,7 @@ "SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定": "The SMTP login password may also be a special passphrase, depending on the specific email service provider's instructions", "PushMe的Key,https://push.i-i.me/": "PushMe key, https://push.i-i.me/", "自建的PushMeServer消息接口地址,例如:http://127.0.0.1:3010,不填则使用官方消息接口": "The self built PushMeServer message interface address, for example: http://127.0.0.1:3010 If left blank, use the official message interface", - "ntfy的url地址,例如 https://ntfy.sh'": "The URL address of ntfy, for example, https://ntfy.sh.", + "ntfy的url地址,例如 https://ntfy.sh": "The URL address of ntfy, for example, https://ntfy.sh.", "ntfy的消息应用topic": "The topic for ntfy's messaging application.", "wxPusherBot的appToken": "wxPusherBot's appToken, obtain according to docs https://wxpusher.zjiecode.com/docs/", "wxPusherBot的topicIds": "wxPusherBot's topicIds, at least one of topicIds or uids must be configured", diff --git a/src/utils/http.ts b/src/utils/http.tsx similarity index 83% rename from src/utils/http.ts rename to src/utils/http.tsx index e276ecdd..af604fb4 100644 --- a/src/utils/http.ts +++ b/src/utils/http.tsx @@ -1,5 +1,5 @@ import intl from 'react-intl-universal'; -import { message } from 'antd'; +import { message, notification } from 'antd'; import config from './config'; import { history } from '@umijs/max'; import axios, { @@ -14,7 +14,7 @@ export interface IResponseData { code?: number; data?: any; message?: string; - error?: any; + errors?: any[]; } export type Override< @@ -41,7 +41,7 @@ const errorHandler = function ( ) { if (error.response) { const msg = error.response.data - ? error.response.data.message || error.message || error.response.data + ? error.response.data.message || error.message : error.response.statusText; const responseStatus = error.response.status; if ([502, 504].includes(responseStatus)) { @@ -57,9 +57,17 @@ const errorHandler = function ( return error.config?.onError(error.response); } - message.error({ - content: msg, - style: { maxWidth: 500, margin: '0 auto' }, + notification.error({ + message: msg, + description: ( + <> + {error.response?.data?.errors?.map((item: any) => ( +
+ {item.message} ({item.value}) +
+ ))} + + ), }); } } else { @@ -107,9 +115,15 @@ _request.interceptors.response.use(async (response) => { if (res.code !== 200) { const msg = res.message || res.data; msg && - message.error({ - content: msg, - style: { maxWidth: 500, margin: '0 auto' }, + notification.error({ + message: msg, + description: ( + <> + {res?.errors.map((item: any) => ( +
{item.message}
+ ))} + + ), }); } return res;