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

    Function toErrorObject

    • Converts any error value to an Error object

      Handles various error types including Error objects, objects with message properties, strings, and other primitives. Essential for consistent error handling across the application.

      Parameters

      • err: unknown

        The error value to convert (can be any type)

      Returns Error

      An Error object with appropriate message

      // Convert Error object (passthrough)
      toErrorObject(new Error('Failed')) // Error: Failed

      // Convert string
      toErrorObject('Network timeout') // Error: Network timeout

      // Convert object with message
      toErrorObject({ message: 'Invalid data' }) // Error: Invalid data

      // Convert number
      toErrorObject(404) // Error: 404

      // Usage in catch blocks
      try {
      await riskyOperation();
      } catch (err) {
      const error = toErrorObject(err);
      logger.error(error.message);
      }