22 lines
474 B
TypeScript
22 lines
474 B
TypeScript
import { FetchBaseQueryError } from '@reduxjs/toolkit/query';
|
|
|
|
import { BaseResponse } from '../../models/api';
|
|
|
|
export const extractBodyFromResponse = <Body>(response: BaseResponse<Body>) => {
|
|
if (response.success) {
|
|
return response.body;
|
|
}
|
|
};
|
|
|
|
export const extractErrorMessageFromResponse = ({
|
|
data,
|
|
}: FetchBaseQueryError) => {
|
|
if (
|
|
typeof data === 'object' &&
|
|
'error' in data &&
|
|
typeof data.error === 'string'
|
|
) {
|
|
return data.error;
|
|
}
|
|
};
|