The default 404 and generic errors html bodies are static members in Application, this makes them trivial to replace if they are static html.

This commit is contained in:
Relintai 2020-11-26 11:32:33 +01:00
parent 4d6e1e5dd9
commit cc8de9ed7f
2 changed files with 8 additions and 4 deletions

View File

@ -22,15 +22,13 @@ void Application::setup_middleware() {
}
void Application::default_fallback_error_handler(int error_code, Request *request) {
std::string body = "<html><body>Internal server error! :(</body></html>";
request->response->setBody(body);
request->response->setBody(default_generic_error_body);
request->finalized = true;
request->send();
}
void Application::default_404_error_handler(int error_code, Request *request) {
std::string body = "<html><body>404 :(</body></html>";
request->response->setBody(body);
request->response->setBody(default_error_404_body);
request->finalized = true;
request->send();
}
@ -144,3 +142,6 @@ std::function<void(int, Request *)> Application::default_error_handler_func = nu
std::vector<std::function<void(Request *)> > Application::middlewares;
Application *Application::_instance = nullptr;
std::string Application::default_error_404_body = "<html><body>404 :(</body></html>";
std::string Application::default_generic_error_body = "<html><body>Internal server error! :(</body></html>";

View File

@ -10,6 +10,9 @@ class Request;
class Application {
public:
static std::string default_error_404_body;
static std::string default_generic_error_body;
static void handle_request(Request *request);
static void send_error(int error_code, Request *request);
static void send_file(const std::string &path, Request *request);