import { describeApiError } from "../utils/apiError.js";

export function unwrapList(res) {
  const data = res?.data;
  if (Array.isArray(data)) return data;
  if (data && typeof data === "object") return Object.values(data);
  return [];
}

export function unwrapData(res) {
  return res?.data ?? null;
}

export function normalizeApiError(err, fallback = "Request failed") {
  return describeApiError(err, fallback);
}
