mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-17 09:34:31 +08:00
修复定时任务查询不存在的订阅报错
This commit is contained in:
+28
-9
@@ -1,29 +1,44 @@
|
||||
import intl from 'react-intl-universal'
|
||||
import intl from 'react-intl-universal';
|
||||
import { message } from 'antd';
|
||||
import config from './config';
|
||||
import { history } from '@umijs/max';
|
||||
import axios, { AxiosError, AxiosInstance, AxiosRequestConfig } from 'axios';
|
||||
import axios, {
|
||||
AxiosError,
|
||||
AxiosInstance,
|
||||
AxiosRequestConfig,
|
||||
AxiosResponse,
|
||||
InternalAxiosRequestConfig,
|
||||
} from 'axios';
|
||||
|
||||
interface IResponseData {
|
||||
export interface IResponseData {
|
||||
code?: number;
|
||||
data?: any;
|
||||
message?: string;
|
||||
error?: any;
|
||||
}
|
||||
|
||||
type Override<
|
||||
export type Override<
|
||||
T,
|
||||
K extends Partial<{ [P in keyof T]: any }> | string,
|
||||
> = K extends string
|
||||
? Omit<T, K> & { [P in keyof T]: T[P] | unknown }
|
||||
: Omit<T, keyof K> & K;
|
||||
|
||||
export interface ICustomConfig {
|
||||
onError?: (res: AxiosResponse<unknown, any>) => void;
|
||||
}
|
||||
|
||||
message.config({
|
||||
duration: 2,
|
||||
});
|
||||
|
||||
const time = Date.now();
|
||||
const errorHandler = function (error: AxiosError) {
|
||||
const errorHandler = function (
|
||||
error: Override<
|
||||
AxiosError<IResponseData>,
|
||||
{ config: InternalAxiosRequestConfig & ICustomConfig }
|
||||
>,
|
||||
) {
|
||||
if (error.response) {
|
||||
const msg = error.response.data
|
||||
? error.response.data.message || error.message || error.response.data
|
||||
@@ -38,6 +53,10 @@ const errorHandler = function (error: AxiosError) {
|
||||
history.push('/login');
|
||||
}
|
||||
} else {
|
||||
if (typeof error.config?.onError === 'function') {
|
||||
return error.config?.onError(error.response);
|
||||
}
|
||||
|
||||
message.error({
|
||||
content: msg,
|
||||
style: { maxWidth: 500, margin: '0 auto' },
|
||||
@@ -105,21 +124,21 @@ export const request = _request as Override<
|
||||
{
|
||||
get<T = IResponseData, D = any>(
|
||||
url: string,
|
||||
config?: AxiosRequestConfig<D>,
|
||||
config?: AxiosRequestConfig<D> & ICustomConfig,
|
||||
): Promise<T>;
|
||||
delete<T = IResponseData, D = any>(
|
||||
url: string,
|
||||
config?: AxiosRequestConfig<D>,
|
||||
config?: AxiosRequestConfig<D> & ICustomConfig,
|
||||
): Promise<T>;
|
||||
post<T = IResponseData, D = any>(
|
||||
url: string,
|
||||
data?: D,
|
||||
config?: AxiosRequestConfig<D>,
|
||||
config?: AxiosRequestConfig<D> & ICustomConfig,
|
||||
): Promise<T>;
|
||||
put<T = IResponseData, D = any>(
|
||||
url: string,
|
||||
data?: D,
|
||||
config?: AxiosRequestConfig<D>,
|
||||
config?: AxiosRequestConfig<D> & ICustomConfig,
|
||||
): Promise<T>;
|
||||
}
|
||||
>;
|
||||
|
||||
Reference in New Issue
Block a user