Download packages/effects/request/src/request-client/modules/interceptor.ts from binhugg3/admin: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/spaces/binhugg3/admin/resolve/main/packages/effects/request/src/request-client/modules/interceptor.ts
- Command line
-
hf download hf://spaces/binhugg3/admin/packages/effects/request/src/request-client/modules/interceptor.ts
-
curl -L -o interceptor.ts https://huggingface.co/spaces/binhugg3/admin/resolve/main/packages/effects/request/src/request-client/modules/interceptor.ts
1.07 kB
| import type { AxiosInstance, AxiosResponse } from 'axios'; | |
| import type { | |
| RequestInterceptorConfig, | |
| ResponseInterceptorConfig, | |
| } from '../types'; | |
| const defaultRequestInterceptorConfig: RequestInterceptorConfig = { | |
| fulfilled: (response) => response, | |
| rejected: (error) => Promise.reject(error), | |
| }; | |
| const defaultResponseInterceptorConfig: ResponseInterceptorConfig = { | |
| fulfilled: (response: AxiosResponse) => response, | |
| rejected: (error) => Promise.reject(error), | |
| }; | |
| class InterceptorManager { | |
| private axiosInstance: AxiosInstance; | |
| constructor(instance: AxiosInstance) { | |
| this.axiosInstance = instance; | |
| } | |
| addRequestInterceptor({ | |
| fulfilled, | |
| rejected, | |
| }: RequestInterceptorConfig = defaultRequestInterceptorConfig) { | |
| this.axiosInstance.interceptors.request.use(fulfilled, rejected); | |
| } | |
| addResponseInterceptor<T = any>({ | |
| fulfilled, | |
| rejected, | |
| }: ResponseInterceptorConfig<T> = defaultResponseInterceptorConfig) { | |
| this.axiosInstance.interceptors.response.use(fulfilled, rejected); | |
| } | |
| } | |
| export { InterceptorManager }; | |