diff --git a/core/http/web_root.cpp b/core/http/web_root.cpp index 44726a6..fc29c96 100644 --- a/core/http/web_root.cpp +++ b/core/http/web_root.cpp @@ -69,13 +69,13 @@ void WebRoot::default_routing_middleware(Object *instance, Request *request) { request->next_stage(); } -void WebRoot::default_fallback_error_handler(int error_code, Request *request) { +void WebRoot::default_fallback_error_handler(Request *request, int error_code) { request->compiled_body = default_generic_error_body; request->send(); } -void WebRoot::default_404_error_handler(int error_code, Request *request) { +void WebRoot::default_404_error_handler(Request *request, int error_code) { request->compiled_body = default_error_404_body; request->send(); } @@ -93,10 +93,22 @@ void WebRoot::handle_request_main(Request *request) { // normal routing WebRouterNode::handle_request_main(request); } -/* -void WebRoot::handle_error_send_request(Request *request, const int error_code) { -}*/ +void WebRoot::handle_error_send_request(Request *request, const int error_code) { + std::function func = error_handler_map[error_code]; + + if (!func) { + if (!default_error_handler_func) { + WebNode::handle_error_send_request(request, error_code); + return; + } + + default_error_handler_func(request, error_code); + return; + } + + func(request, error_code); +} bool WebRoot::try_send_wwwroot_file(Request *request) { const String &path = request->get_path_full(); @@ -111,14 +123,7 @@ bool WebRoot::try_send_wwwroot_file(Request *request) { } void WebRoot::send_error(int error_code, Request *request) { - std::function func = error_handler_map[error_code]; - if (!func) { - default_error_handler_func(error_code, request); - return; - } - - func(error_code, request); } void WebRoot::send_file(const std::string &path, Request *request) { diff --git a/core/http/web_root.h b/core/http/web_root.h index 694787f..0b0267d 100644 --- a/core/http/web_root.h +++ b/core/http/web_root.h @@ -35,14 +35,14 @@ public: static std::string default_generic_error_body; void handle_request_main(Request *request); - //void handle_error_send_request(Request *request, const int error_code); + void handle_error_send_request(Request *request, const int error_code); bool try_send_wwwroot_file(Request *request); void send_error(int error_code, Request *request); void send_file(const std::string &path, Request *request); - static void default_fallback_error_handler(int error_code, Request *request); - static void default_404_error_handler(int error_code, Request *request); + static void default_fallback_error_handler(Request *request, int error_code); + static void default_404_error_handler(Request *request, int error_code); virtual void load_settings(); virtual void setup_routes(); @@ -66,8 +66,8 @@ public: std::map main_route_map; std::vector middlewares; - std::map > error_handler_map; - std::function default_error_handler_func; + std::map > error_handler_map; + std::function default_error_handler_func; protected: std::mutex _update_registered_requests_mutex;