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' && 'message' in data && typeof data.message === 'string') {
    return data.message;
  }
};