@eloritzkovitz/server-essentials
    Preparing search index...

    Function handleError

    • Handles errors in controller functions by logging and sending a generic response.

      • Logs the error message and error object.
      • Sends a generic error response in production.
      • Optionally includes error details in development for debugging.
      • Supports custom error codes.

      Parameters

      • res: Response

        The Express response object.

      • message: string

        The error message to log and send.

      • Optionalerror: unknown

        The error object (optional, for logging).

      • status: number = 500

        The HTTP status code (default: 500).

      • Optionalcode: string

        Optional custom error code for the response.

      Returns void

      handleError(res, "Failed to fetch user", err, 404, "USER_NOT_FOUND");