MSP-3104 add roleService
This commit is contained in:
1 parent
e1afa417ee
commit
89151474b7
5 files changed
+111
-14
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import { BaseQueryFn, retry } from '@reduxjs/toolkit/query/react';
|
||||
|
||||
import { AxiosError, AxiosRequestConfig } from 'axios';
|
||||
import { apiService } from '@services/apiService.ts'
|
||||
import { MSPError } from '@type/index.ts'
|
||||
|
||||
export const axiosBaseQuery =
|
||||
(
|
||||
{ baseUrl }: { baseUrl: string } = { baseUrl: '' },
|
||||
): BaseQueryFn<
|
||||
{
|
||||
url: string;
|
||||
method?: AxiosRequestConfig['method'];
|
||||
data?: AxiosRequestConfig['data'];
|
||||
params?: AxiosRequestConfig['params'];
|
||||
},
|
||||
unknown,
|
||||
unknown
|
||||
> =>
|
||||
async ({ url, method = 'post', data, params }) => {
|
||||
try {
|
||||
const result = await apiService({
|
||||
url: baseUrl + url,
|
||||
method,
|
||||
data,
|
||||
params,
|
||||
});
|
||||
return { data: result.data };
|
||||
} catch (axiosError) {
|
||||
const err = axiosError as AxiosError<MSPError>;
|
||||
return {
|
||||
error: { ...err.response },
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export const staggeredBaseQueryWithBailOut = (baseUrl: string) =>
|
||||
retry(
|
||||
async (args: string | AxiosRequestConfig['data'], api, extraOptions) => {
|
||||
const result = await axiosBaseQuery({ baseUrl })(args, api, extraOptions);
|
||||
const error = result.error as AxiosError<MSPError>;
|
||||
if (error && error?.status === 400) {
|
||||
retry.fail(result.error);
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
{
|
||||
maxRetries: 5,
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user