| 11 | export type ResponseTransform<Input = any, Output = any> = (input: Input) => Output | Promise<Output>; |
| 12 | |
| 13 | export interface RequestOption< |
| 14 | ResponseData, |
| 15 | ApiData = ResponseData, |
| 16 | State extends Record<string, unknown> = Record<string, unknown> |
| 17 | > { |
| 18 | /** |
| 19 | * The default state |
| 20 | */ |
| 21 | defaultState?: State; |
| 22 | /** |
| 23 | * transform the response data to the api data |
| 24 | * |
| 25 | * @param response Axios response |
| 26 | */ |
| 27 | transform: ResponseTransform<AxiosResponse<ResponseData>, ApiData>; |
| 28 | /** |
| 29 | * transform the response data to the api data |
| 30 | * |
| 31 | * @deprecated use `transform` instead, will be removed in the next major version v3 |
| 32 | * @param response Axios response |
| 33 | */ |
| 34 | transformBackendResponse: ResponseTransform<AxiosResponse<ResponseData>, ApiData>; |
| 35 | /** |
| 36 | * The hook before request |
| 37 | * |
| 38 | * For example: You can add header token in this hook |
| 39 | * |
| 40 | * @param config Axios config |
| 41 | */ |
| 42 | onRequest: (config: InternalAxiosRequestConfig) => InternalAxiosRequestConfig | Promise<InternalAxiosRequestConfig>; |
| 43 | /** |
| 44 | * The hook to check backend response is success or not |
| 45 | * |
| 46 | * @param response Axios response |
| 47 | */ |
| 48 | isBackendSuccess: (response: AxiosResponse<ResponseData>) => boolean; |
| 49 | /** |
| 50 | * The hook after backend request fail |
| 51 | * |
| 52 | * For example: You can handle the expired token in this hook |
| 53 | * |
| 54 | * @param response Axios response |
| 55 | * @param instance Axios instance |
| 56 | */ |
| 57 | onBackendFail: ( |
| 58 | response: AxiosResponse<ResponseData>, |
| 59 | instance: AxiosInstance |
| 60 | ) => Promise<AxiosResponse | null> | Promise<void>; |
| 61 | /** |
| 62 | * The hook to handle error |
| 63 | * |
| 64 | * For example: You can show error message in this hook |
| 65 | * |
| 66 | * @param error |
| 67 | */ |
| 68 | onError: (error: AxiosError<ResponseData>) => void | Promise<void>; |
| 69 | } |
| 70 |
nothing calls this directly
no outgoing calls
no test coverage detected