getErrorMessage.ts 267 B

123456789
  1. export const getErrorMessage = (
  2. error: unknown,
  3. defaultErrorMessage: string | null = null
  4. ) => {
  5. if (error instanceof Error) return error.message;
  6. if (error) return String(error);
  7. if (defaultErrorMessage) return defaultErrorMessage;
  8. return "Unknown error";
  9. };