Shared:Utils:Axios: add generic for API types

This commit is contained in:
Timofey Boyko 2024-08-15 16:18:59 +03:00
parent 56d9c6e774
commit ada7d8c960
3 changed files with 15 additions and 6 deletions

View File

@ -33,12 +33,12 @@ export const initSSR = (headers: Record<string, string>) => {
client.initSSR(headers);
};
export const request = (
export const request = <T>(
options: TReqOption & AxiosRequestConfig,
skipRedirect = false,
isOAuth = false,
) => {
return client.request(options, skipRedirect, isOAuth);
): Promise<T> | undefined => {
return client.request<T>(options, skipRedirect, isOAuth);
};
export const setWithCredentialsStatus = (state: boolean) => {

View File

@ -182,11 +182,11 @@ class AxiosClient {
}
};
request = (
request = <T>(
options: TReqOption & AxiosRequestConfig,
skipRedirect = false,
isOAuth = false,
) => {
): Promise<T> | undefined => {
const onSuccess = (response: TRes) => {
const error = this.getResponseError(response);
@ -295,7 +295,9 @@ class AxiosClient {
return Promise.reject(error);
};
return this.client?.(options).then(onSuccess).catch(onError);
return this.client?.(options).then(onSuccess).catch(onError) as
| Promise<T>
| undefined;
};
}

View File

@ -150,3 +150,10 @@ export type IClientListProps = List<IClientProps>;
export type IClientListDTO = List<IClientResDTO>;
export type TConsentList = List<TConsentData>;
export type TGenerateDeveloperToken = {
access_token: string;
expires_in: number;
scope: string;
token_type: string;
};