This documentation is for version v1.3.0 of NNG, but the latest released version is v1.8.0. see the documentation for v1.8.0 for the most up-to-date information.


#include <nng/nng.h>
#include <nng/supplemental/http/http.h>

int nng_http_server_set_error_file(nng_http_server *server,
uint16_t code, const char *path);


The nng_http_server_set_error_file() sets an error page to be used for HTTP status code on the server instance server. The body content of the HTTP responses will contain the file contents of the file located at path, which should be an HTML file.

The custom HTML content will be used when the server is returning an internally generated error response, or is returning an error response that was allocated with the nng_http_res_alloc_error() function. This HTML content will also be used if the application calls the nng_http_server_res_error(). The last custom error page set for code by either this function or xref:`nng_http_server_set_error_page.3http.adoc[nng_http_server_error_page()] will be used.

Error responses that have their body content changed after allocation, or that are written directly by the application, will not use the body content supplied here.
The file contents of path are read when this function is called. Therefore, if the file contents are changed, then this function should be called again to update the error page.


This function returns 0 on success, and non-zero otherwise.



The file named by path does not exist.


No permission to read the file named by path.


Insufficient free memory exists.


HTTP not supported.