$darkmode
Kourier 1.0.0
Kourier::ErrorHandler Class Referenceabstract

The ErrorHandler class defines the interface for HttpServer error handlers. More...

#include <ErrorHandler.h>

Public Member Functions

virtual void handleError (HttpServer::ServerError error, std::string_view clientIp, uint16_t clientPort)=0
 

Detailed Description

The ErrorHandler class defines the interface for HttpServer error handlers.

Although HTTP supports communication of errors in responses, some errors cannot be handled this way.

For example, a request may not be valid HTTP or, even if it is valid, no handler may be mapped to the request's method/path. Also, the request may be too big, or a timeout may occur while waiting for requests or parsing them. Error handlers exist to allow you to take action when such events occur. You can call HttpServer::setErrorHandler to set the error handler for a HttpServer instance.

Member Function Documentation

◆ handleError()

virtual void Kourier::ErrorHandler::handleError ( HttpServer::ServerError  error,
std::string_view  clientIp,
uint16_t  clientPort 
)
pure virtual

HttpServer calls handleError when an error occurs while processing the HTTP request. HttpServer calls the error handler set by you when it processes an invalid HTTP request, when the request is valid but has no handler mapped to its method/path, or when a timeout occurs while waiting for a request or while parsing one.

You can use error to know which type of error happened. The client IP/port is given by clientIP and clientPort, respectively. HttpServer does not serialize access to this method. Thus, it is your responsibility to provide a thread-safe implementation for it.