CIA Compliance Manager API Documentation - v1.1.6
    Preparing search index...

    Variable formatError

    formatError: (err: unknown, prefix?: string) => string

    Type Declaration

      • (err: unknown, prefix?: string): string
      • Formats an error for consistent logging with optional prefix

        Converts errors to formatted strings suitable for logging, with optional contextual prefix for better error traceability. Handles unknown error types safely.

        Parameters

        • err: unknown

          The error to format (can be any type)

        • Optionalprefix: string

          Optional prefix for context (e.g., 'API', 'Database', 'Widget')

        Returns string

        A formatted error message string

        // Without prefix
        formatError(new Error('Connection failed'))
        // 'Connection failed'

        // With prefix for context
        formatError(new Error('Timeout'), 'API Call')
        // 'API Call: Timeout'

        formatError('Invalid input', 'Validation')
        // 'Validation: Invalid input'

        // Usage in service methods
        try {
        await fetchData();
        } catch (err) {
        const message = formatError(err, 'DataService');
        console.error(message); // 'DataService: Network error'
        }