CIA Compliance Manager — API Documentation - v1.1.50
    Preparing search index...

    Function formatError

    • 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'
      }