@acrool/react-fetcher 0.0.6-alpha.0 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -57,7 +57,7 @@ import "@acrool/react-fetcher/dist/index.css";
57
57
  Wrap your app with `AuthStateProvider` and `AxiosClientProvider`. It is recommended to use `AppFetcherProvider` to automatically wrap all necessary providers:
58
58
 
59
59
  ```tsx
60
- import AppFetcherProvider from '@/library/acrool-react-fetcher';
60
+ import AppFetcherProvider from '@/library/react-fetcher';
61
61
 
62
62
  ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
63
63
  <AppFetcherProvider>
@@ -73,7 +73,7 @@ For Redux Toolkit Query, create `baseApi.ts`:
73
73
  ```ts
74
74
  import { createGraphQLFetcher } from '@acrool/react-fetcher';
75
75
  import { createApi } from '@reduxjs/toolkit/query/react';
76
- import { axiosInstance } from '@/library/acrool-react-fetcher';
76
+ import { axiosInstance } from '@/library/react-fetcher';
77
77
 
78
78
  export const baseApi = createApi({
79
79
  reducerPath: 'api',
@@ -1,2 +1,2 @@
1
1
  export { default as AuthStateProvider, useAuthState } from './AuthStateProvider';
2
- export type { IAuthTokens } from './types';
2
+ export type { IAuthTokens, TOnForceLogout, TOnGetTokens, TOnRefreshToken, TOnSetTokens } from './types';
@@ -1,16 +1,15 @@
1
1
  import { AxiosInstance } from 'axios';
2
2
  import { default as React } from 'react';
3
- import { IInternalRequestConfig } from '../fetchers/types';
4
- import { IFormatResponseErrorReturn, TGetResponseFormatError } from './types';
3
+ import { TCheckIsRefreshTokenRequest, TGetResponseFormatError, TResponseOnErrorCallback } from './types';
5
4
  export declare const AxiosClientContext: React.Context<AxiosInstance | null>;
6
5
  export declare const useAxiosClient: () => null;
7
6
  interface IProps {
8
7
  children: React.ReactNode;
9
8
  axiosInstance: AxiosInstance;
10
- checkIsRefreshTokenRequest?: (config: IInternalRequestConfig) => boolean;
9
+ checkIsRefreshTokenRequest?: TCheckIsRefreshTokenRequest;
11
10
  locale?: string;
12
11
  getResponseFormatError?: TGetResponseFormatError;
13
- onError?: (error: IFormatResponseErrorReturn) => void;
12
+ onError?: TResponseOnErrorCallback;
14
13
  authorizationPrefix?: string;
15
14
  isDebug?: boolean;
16
15
  }
@@ -1,3 +1,3 @@
1
1
  export { default as FetcherProvider } from './FetcherProvider';
2
2
  export { getGraphQLResponseFormatError, getRestFulResponseFormatError } from './utils';
3
- export type { TGetResponseFormatError, IFormatResponseErrorReturn } from './types';
3
+ export type { TGetResponseFormatError, IFormatResponseErrorReturn, TResponseOnErrorCallback, TCheckIsRefreshTokenRequest } from './types';
@@ -1,4 +1,5 @@
1
1
  import { AxiosError, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
2
+ import { IInternalRequestConfig } from '../fetchers/types';
2
3
  export type TInterceptorRequest = (value: InternalAxiosRequestConfig<any>) => InternalAxiosRequestConfig<any> | Promise<InternalAxiosRequestConfig<any>>;
3
4
  export type TInterceptorResponseSuccess = (value: AxiosResponse<any>) => AxiosResponse<any> | Promise<AxiosResponse<any>>;
4
5
  export type TInterceptorResponseError = (error: AxiosError<any>) => AxiosResponse<any> | Promise<AxiosResponse<any>>;
@@ -9,3 +10,5 @@ export interface IFormatResponseErrorReturn {
9
10
  args?: any;
10
11
  }
11
12
  export type TGetResponseFormatError = (axiosError?: AxiosError) => IFormatResponseErrorReturn;
13
+ export type TCheckIsRefreshTokenRequest = (config: IInternalRequestConfig) => boolean;
14
+ export type TResponseOnErrorCallback = (error: IFormatResponseErrorReturn) => void;
@@ -771,7 +771,7 @@ const FetcherProvider = ({
771
771
  const status = axiosError.status;
772
772
  const responseFirstError = getResponseFormatError(axiosError);
773
773
  if (isDebug) u.warning("[FetcherProvider] interceptorsResponseError", { status, responseFirstError });
774
- if (onError) {
774
+ if (onError && originalConfig.ignoreErrorCallback !== true) {
775
775
  onError(responseFirstError);
776
776
  }
777
777
  const isRefresh = originalConfig && checkIsRefreshTokenRequest ? checkIsRefreshTokenRequest(originalConfig) : false;