import axios from 'axios';

/**
 * Safely extract an error message from an unknown error value.
 * Handles Axios errors (API responses), standard Error objects, and fallback.
 */
export function getErrorMessage(err: unknown, fallback: string): string {
  if (axios.isAxiosError(err)) {
    return err.response?.data?.message || err.response?.data?.error?.message || fallback;
  }
  if (err instanceof Error) {
    return err.message;
  }
  return fallback;
}
