2025-02-16 11:31:26 +03:00
|
|
|
import { FetchBaseQueryError } from '@reduxjs/toolkit/query';
|
2025-01-26 19:20:36 +03:00
|
|
|
|
2025-02-16 11:31:26 +03:00
|
|
|
import { BaseResponse } from '../../models/api';
|
2025-01-26 19:20:36 +03:00
|
|
|
|
|
|
|
export const extractBodyFromResponse = <Body>(response: BaseResponse<Body>) => {
|
|
|
|
if (response.success) {
|
|
|
|
return response.body;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2025-02-16 11:31:26 +03:00
|
|
|
export const extractErrorMessageFromResponse = ({
|
|
|
|
data,
|
|
|
|
}: FetchBaseQueryError) => {
|
|
|
|
if (
|
|
|
|
typeof data === 'object' &&
|
|
|
|
'message' in data &&
|
|
|
|
typeof data.message === 'string'
|
|
|
|
) {
|
2025-01-26 19:20:36 +03:00
|
|
|
return data.message;
|
|
|
|
}
|
2025-02-02 11:59:27 +03:00
|
|
|
};
|