2021-05-24 20:26:33 +08:00
|
|
|
import { AxiosAdapterTask } from './adapter';
|
2021-05-21 14:26:22 +08:00
|
|
|
import { AxiosRequestConfig, AxiosResponse, AxiosResponseError } from './Axios';
|
2021-05-11 10:22:44 +08:00
|
|
|
|
2021-05-21 14:26:22 +08:00
|
|
|
export type AxiosErrorResponse = AxiosResponse | AxiosResponseError;
|
|
|
|
|
|
|
|
class AxiosError extends Error {
|
2021-05-11 10:22:44 +08:00
|
|
|
public isAxiosError = true;
|
|
|
|
|
2021-05-21 14:26:22 +08:00
|
|
|
public config: AxiosRequestConfig;
|
|
|
|
|
2021-05-24 20:26:33 +08:00
|
|
|
public request?: AxiosAdapterTask;
|
2021-05-21 14:26:22 +08:00
|
|
|
|
|
|
|
public response?: AxiosErrorResponse;
|
|
|
|
|
2021-05-11 10:22:44 +08:00
|
|
|
public constructor(
|
|
|
|
message: string,
|
2021-05-21 14:26:22 +08:00
|
|
|
config: AxiosRequestConfig,
|
2021-05-24 20:26:33 +08:00
|
|
|
request?: AxiosAdapterTask,
|
2021-05-21 14:26:22 +08:00
|
|
|
response?: AxiosErrorResponse,
|
2021-05-11 10:22:44 +08:00
|
|
|
) {
|
|
|
|
super(message);
|
|
|
|
|
2021-05-21 14:26:22 +08:00
|
|
|
this.config = config;
|
|
|
|
this.request = request;
|
|
|
|
this.response = response;
|
|
|
|
|
|
|
|
Object.setPrototypeOf(this, AxiosError.prototype);
|
2021-05-11 10:22:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-21 14:26:22 +08:00
|
|
|
export function createError(
|
2021-05-11 10:22:44 +08:00
|
|
|
message: string,
|
|
|
|
config: AxiosRequestConfig,
|
2021-05-24 20:26:33 +08:00
|
|
|
request?: AxiosAdapterTask,
|
2021-05-21 14:26:22 +08:00
|
|
|
response?: AxiosErrorResponse,
|
2021-05-11 10:22:44 +08:00
|
|
|
): AxiosError {
|
2021-05-21 14:26:22 +08:00
|
|
|
return new AxiosError(message, config, request, response);
|
2021-05-11 10:22:44 +08:00
|
|
|
}
|