Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

835 B
Raw Blame
/**
 * Pulls the server-provided error string out of an axios-style error so the UI can
 * surface the real reason (e.g. a Google Places API message such as "Places API (New)
 * has not been used in project … or it is disabled") instead of a generic fallback.
 */
export function getApiErrorMessage(err: unknown, fallback: string): string {
  const message = (err as { response?: { data?: { error?: unknown } } })?.response?.data?.error
  return typeof message === 'string' && message.trim() ? message : fallback
}

/** The `code` a refusal names its reason with, beside its message; null when it carries none. */
export function getApiErrorCode(err: unknown): string | null {
  const code = (err as { response?: { data?: { code?: unknown } } } | null)?.response?.data?.code
  return typeof code === 'string' && code ? code : null
}