Function expressErrorHandler

Error handling middleware for Express applications.

This middleware is designed to handle errors thrown during request processing. It checks whether the error is an instance of ClientError or ServerError and responds accordingly. If the error is not recognized, it defaults to creating a ServerError instance to provide a standardized error response.

  • Parameters

    • err: any
    • req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>

      The Express request object.

    • res: Response<any, Record<string, any>, number>

      The Express response object.

    • next: NextFunction

      The next middleware function in the stack.

    Returns void | Promise<void>

    Responds to the client with an appropriate error message.