Skip to content

Commit

Permalink
修改错误提示
Browse files Browse the repository at this point in the history
  • Loading branch information
whyour committed Jan 14, 2025
1 parent a508522 commit af97543
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
4 changes: 2 additions & 2 deletions back/loaders/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
32 changes: 23 additions & 9 deletions src/utils/http.ts → src/utils/http.tsx
Original file line number Diff line number Diff line change
@@ -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, {
Expand All @@ -14,7 +14,7 @@ export interface IResponseData {
code?: number;
data?: any;
message?: string;
error?: any;
errors?: any[];
}

export type Override<
Expand All @@ -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)) {
Expand All @@ -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) => (
<div>
{item.message} ({item.value})
</div>
))}
</>
),
});
}
} else {
Expand Down Expand Up @@ -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) => (
<div>{item.message}</div>
))}
</>
),
});
}
return res;
Expand Down

0 comments on commit af97543

Please sign in to comment.