From 214bb19438eff6a72e3cc8799ca3cbb918266756 Mon Sep 17 00:00:00 2001 From: divyam234 <47589864+divyam234@users.noreply.github.com> Date: Wed, 14 Feb 2024 23:05:24 +0530 Subject: [PATCH] fix: error types --- src/index.ts | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/index.ts b/src/index.ts index 7c38086..eab4704 100644 --- a/src/index.ts +++ b/src/index.ts @@ -161,7 +161,7 @@ async function request( signal: options.signal, }); - if (interceptors && interceptors.request.length >0) { + if (interceptors && interceptors.request.length > 0) { const chain = interceptors.request .filter( (interceptor) => @@ -369,29 +369,29 @@ class AxiosInterceptorManager { this.#interceptors = []; }; - map=(fn: (value: AxiosInterceptor, index: number) => U)=>{ + map = (fn: (value: AxiosInterceptor, index: number) => U) => { return this.#interceptors.map(fn); - } + }; - filter=(fn: (value: AxiosInterceptor) => boolean)=>{ + filter = (fn: (value: AxiosInterceptor) => boolean) => { return this.#interceptors.filter(fn); - } + }; - get length(){ + get length() { return this.#interceptors.length; } } -export function isAxiosError(payload: any) { - if ( +export function isAxiosError( + payload: any, +): payload is AxiosError { + return ( payload !== null && typeof payload === "object" && (payload as AxiosError).isAxiosError - ) { - return true; - } - return false; + ); } + function createAxiosInstance(defaults?: CreateAxiosDefaults) { const axiosInstance = new Axios(defaults); @@ -404,9 +404,17 @@ function createAxiosInstance(defaults?: CreateAxiosDefaults) { axios.interceptors = axiosInstance.interceptors; - ["get", "delete", "head", "options", "post", "put", "patch", "all","request"].forEach( - (method) => (axios[method] = axiosInstance[method]), - ); + [ + "get", + "delete", + "head", + "options", + "post", + "put", + "patch", + "all", + "request", + ].forEach((method) => (axios[method] = axiosInstance[method])); return axios as AxiosInstance; }