Reworked error handling.

This commit is contained in:
Relintai 2022-01-08 11:47:39 +01:00
parent 413e9efbc8
commit fd106fc785
5 changed files with 19 additions and 1 deletions

View File

@ -108,7 +108,7 @@ void Request::send_file(const String &p_file_path) {
}
void Request::send_error(int error_code) {
server->get_web_root()->send_error(error_code, this);
server->get_web_root()->handle_error_send_request(this, error_code);
}
void Request::reset() {

View File

@ -2,6 +2,7 @@
#include "web_node.h"
#include "request.h"
#include "http_enums.h"
#include "core/settings/settings.h"
@ -70,6 +71,14 @@ void WebNode::set_database(Database *db) {
void WebNode::handle_request_main(Request *request) {
}
void WebNode::handle_error_send_request(Request *request, const int error_code) {
//this is a fallback error handler.
//Webroot implements a proper one
request->compiled_body = "<html><body>Internal server error!</body></html>";
request->set_status_code(HTTP_STATUS_CODE_503_SERVICE_UNAVAILABLE);
request->send();
}
void WebNode::create_validators() {
}

View File

@ -3,6 +3,7 @@
#include "core/nodes/node.h"
#include "core/reference.h"
#include "core/variant.h"
class Request;
class Settings;
@ -31,6 +32,8 @@ public:
#endif
virtual void handle_request_main(Request *request);
virtual void handle_error_send_request(Request *request, const int error_code);
virtual void create_validators();
virtual void create_table();

View File

@ -93,6 +93,10 @@ 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) {
}*/
bool WebRoot::try_send_wwwroot_file(Request *request) {
const String &path = request->get_path_full();

View File

@ -35,6 +35,8 @@ 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);
bool try_send_wwwroot_file(Request *request);
void send_error(int error_code, Request *request);
void send_file(const std::string &path, Request *request);