export const getApiErrorMessage = async (
  error,
  fallback = 'Произошла ошибка',
) => {
  const data = error?.response?.data;

  if (!data) {
    return error?.message || fallback;
  }

  if (data instanceof Blob) {
    try {
      const text = await data.text();
      const json = JSON.parse(text);
      return json.message || json.detail || text || fallback;
    } catch {
      return fallback;
    }
  }

  if (typeof data === 'string') {
    return data || fallback;
  }

  return data.message || data.detail || fallback;
};
