feat: add httpConfig to CustomClientOptions and allow it to override anything via optionsToConfig
This commit is contained in:
parent
c1b55c5d98
commit
6bdc43dd85
11
src/axios.ts
11
src/axios.ts
|
@ -25,12 +25,17 @@ export const customInstance = <T>(
|
||||||
...config,
|
...config,
|
||||||
...options,
|
...options,
|
||||||
cancelToken: source.token,
|
cancelToken: source.token,
|
||||||
}).then(({data}) => data).catch((error) => {
|
})
|
||||||
|
.then(({ data }) => data)
|
||||||
|
.catch((error) => {
|
||||||
if (Axios.isCancel(error)) {
|
if (Axios.isCancel(error)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new S5Error((error as AxiosError).message, (error as AxiosError).response?.status as number);
|
throw new S5Error(
|
||||||
})
|
(error as AxiosError).message,
|
||||||
|
(error as AxiosError).response?.status as number,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
promise.cancel = () => {
|
promise.cancel = () => {
|
||||||
|
|
|
@ -18,6 +18,7 @@ export type CustomClientOptions = {
|
||||||
customCookie?: string;
|
customCookie?: string;
|
||||||
onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void;
|
onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void;
|
||||||
onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
|
onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
|
||||||
|
httpConfig?: AxiosRequestConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function optionsToConfig(
|
export function optionsToConfig(
|
||||||
|
@ -29,7 +30,7 @@ export function optionsToConfig(
|
||||||
| CustomRegistryOptions
|
| CustomRegistryOptions
|
||||||
)[]
|
)[]
|
||||||
): AxiosRequestConfig {
|
): AxiosRequestConfig {
|
||||||
const config: AxiosRequestConfig = {};
|
let config: AxiosRequestConfig = {};
|
||||||
|
|
||||||
config.baseURL = client.portalUrl;
|
config.baseURL = client.portalUrl;
|
||||||
|
|
||||||
|
@ -75,5 +76,12 @@ export function optionsToConfig(
|
||||||
|
|
||||||
config.headers = headers;
|
config.headers = headers;
|
||||||
|
|
||||||
|
if (finalOptions?.httpConfig) {
|
||||||
|
config = {
|
||||||
|
...config,
|
||||||
|
...finalOptions.httpConfig,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue