mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-17 09:34:31 +08:00
修改错误提示
This commit is contained in:
@@ -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) => (
|
||||
<div>
|
||||
{item.message} ({item.value})
|
||||
</div>
|
||||
))}
|
||||
</>
|
||||
),
|
||||
});
|
||||
}
|
||||
} 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) => (
|
||||
<div>{item.message}</div>
|
||||
))}
|
||||
</>
|
||||
),
|
||||
});
|
||||
}
|
||||
return res;
|
||||
Reference in New Issue
Block a user