UNPKG

@cranberry-money/shared-utils

Version:

Shared utility functions for Blueberry platform

40 lines 1.57 kB
import type { UserFriendlyError } from '@cranberry-money/shared-types'; /** * Creates a user-friendly error with a clean message for display * while preserving the original error for debugging. * * @param message - The user-friendly message to display * @param originalError - The original error for debugging purposes * @returns A UserFriendlyError instance */ export declare function createUserFriendlyError(message: string, originalError?: unknown): UserFriendlyError; /** * Type guard to check if an error is a UserFriendlyError * * @param error - The error to check * @returns True if the error is a UserFriendlyError */ export declare function isUserFriendlyError(error: unknown): error is UserFriendlyError; /** * Extracts a human-readable error message from various error types. * Handles axios errors, standard Error objects, strings, and unknown types. * * @param error - The error to extract a message from * @param defaultMessage - Optional default message if no message can be extracted * @returns The error message string, or null if no error * * @example * // Axios error * getErrorMessage(axiosError) // Returns response.data.message if available * * // Standard Error * getErrorMessage(new Error('Something went wrong')) // Returns 'Something went wrong' * * // String * getErrorMessage('Failed to load') // Returns 'Failed to load' * * // No error * getErrorMessage(null) // Returns null */ export declare function getErrorMessage(error: unknown, defaultMessage?: string): string | null; //# sourceMappingURL=errors.d.ts.map