/** Normalize an axios/fetch error into a human-readable message. */
export function describeApiError(err, fallback = "Something went wrong") {
  const data = err?.response?.data;
  if (data) {
    if (typeof data === "string" && data.trim()) return data;
    if (data.message) return data.message;
    if (data.error) return data.error;
    if (Array.isArray(data.details) && data.details.length) {
      return data.details.join(", ");
    }
  }
  if (err?.message) return err.message;
  return fallback;
}

export function statusOf(err) {
  return err?.response?.status ?? null;
}
