From cc8de9ed7f91224377e6b76c79c6dd788d25fad0 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 26 Nov 2020 11:32:33 +0100 Subject: [PATCH] The default 404 and generic errors html bodies are static members in Application, this makes them trivial to replace if they are static html. --- core/application.cpp | 9 +++++---- core/application.h | 3 +++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/application.cpp b/core/application.cpp index ce9b555..6a546da 100644 --- a/core/application.cpp +++ b/core/application.cpp @@ -22,15 +22,13 @@ void Application::setup_middleware() { } void Application::default_fallback_error_handler(int error_code, Request *request) { - std::string body = "Internal server error! :("; - 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 = "404 :("; - request->response->setBody(body); + request->response->setBody(default_error_404_body); request->finalized = true; request->send(); } @@ -144,3 +142,6 @@ std::function Application::default_error_handler_func = nu std::vector > Application::middlewares; Application *Application::_instance = nullptr; + +std::string Application::default_error_404_body = "404 :("; +std::string Application::default_generic_error_body = "Internal server error! :("; diff --git a/core/application.h b/core/application.h index 5b7f770..67f0f36 100644 --- a/core/application.h +++ b/core/application.h @@ -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);