import { AxiosError } from "axios";
/**
* Format error messages in a user-friendly way
*/
export function formatError(error: unknown): string {
if (error instanceof AxiosError) {
const status = error.response?.status;
const detail = error.response?.data?.Detail;
switch (status) {
case 401:
return "Authentication failed. Please check your Xero credentials.";
case 403:
return "You don't have permission to access this resource in Xero.";
case 404:
return "The requested resource was not found in Xero.";
case 429:
return "Too many requests to Xero. Please try again in a moment.";
default:
return detail || "An error occurred while communicating with Xero.";
}
}
return error instanceof Error
? error.message
: `An unexpected error occurred: ${error}`;
}