修改错误提示

This commit is contained in:
whyour 2025-01-14 23:20:53 +08:00
parent a508522872
commit af97543918
3 changed files with 26 additions and 12 deletions

View File

@ -159,8 +159,8 @@ export default ({ app }: { app: Application }) => {
.status(500) .status(500)
.send({ .send({
code: 400, code: 400,
message: `${err.name} ${err.message}`, message: `${err.message}`,
validation: err.errors, errors: err.errors,
}) })
.end(); .end();
} }

View File

@ -393,7 +393,7 @@
"SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定": "The SMTP login password may also be a special passphrase, depending on the specific email service provider's instructions", "SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定": "The SMTP login password may also be a special passphrase, depending on the specific email service provider's instructions",
"PushMe的Keyhttps://push.i-i.me/": "PushMe key, https://push.i-i.me/", "PushMe的Keyhttps://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", "自建的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.", "ntfy的消息应用topic": "The topic for ntfy's messaging application.",
"wxPusherBot的appToken": "wxPusherBot's appToken, obtain according to docs https://wxpusher.zjiecode.com/docs/", "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", "wxPusherBot的topicIds": "wxPusherBot's topicIds, at least one of topicIds or uids must be configured",

View File

@ -1,5 +1,5 @@
import intl from 'react-intl-universal'; import intl from 'react-intl-universal';
import { message } from 'antd'; import { message, notification } from 'antd';
import config from './config'; import config from './config';
import { history } from '@umijs/max'; import { history } from '@umijs/max';
import axios, { import axios, {
@ -14,7 +14,7 @@ export interface IResponseData {
code?: number; code?: number;
data?: any; data?: any;
message?: string; message?: string;
error?: any; errors?: any[];
} }
export type Override< export type Override<
@ -41,7 +41,7 @@ const errorHandler = function (
) { ) {
if (error.response) { if (error.response) {
const msg = error.response.data const msg = error.response.data
? error.response.data.message || error.message || error.response.data ? error.response.data.message || error.message
: error.response.statusText; : error.response.statusText;
const responseStatus = error.response.status; const responseStatus = error.response.status;
if ([502, 504].includes(responseStatus)) { if ([502, 504].includes(responseStatus)) {
@ -57,9 +57,17 @@ const errorHandler = function (
return error.config?.onError(error.response); return error.config?.onError(error.response);
} }
message.error({ notification.error({
content: msg, message: msg,
style: { maxWidth: 500, margin: '0 auto' }, description: (
<>
{error.response?.data?.errors?.map((item: any) => (
<div>
{item.message} ({item.value})
</div>
))}
</>
),
}); });
} }
} else { } else {
@ -107,9 +115,15 @@ _request.interceptors.response.use(async (response) => {
if (res.code !== 200) { if (res.code !== 200) {
const msg = res.message || res.data; const msg = res.message || res.data;
msg && msg &&
message.error({ notification.error({
content: msg, message: msg,
style: { maxWidth: 500, margin: '0 auto' }, description: (
<>
{res?.errors.map((item: any) => (
<div>{item.message}</div>
))}
</>
),
}); });
} }
return res; return res;