diff --git a/400.html b/400.html
new file mode 100644
index 0000000..1dd4625
--- /dev/null
+++ b/400.html
@@ -0,0 +1,73 @@
+
+
+
+
+ 400 Bad Request
+
+
+
+
+
+
400
+
Oops! Bad Request.
Your browser sent a request that this server could not understand.
+
Go Home
+
+
+
\ No newline at end of file
diff --git a/config/default.conf b/config/default.conf
index 93fd93b..25e0f23 100644
--- a/config/default.conf
+++ b/config/default.conf
@@ -1,4 +1,7 @@
autoindex on
+error_page 400 ./400.html
+
+
server {
listen 8080;
diff --git a/webserv/config/ConfigManager.cpp b/webserv/config/ConfigManager.cpp
index 4c8beb9..9124fed 100644
--- a/webserv/config/ConfigManager.cpp
+++ b/webserv/config/ConfigManager.cpp
@@ -95,4 +95,13 @@ ServerConfig *ConfigManager::getMatchingServerConfig(const std::string &host, in
}
Log::warning("No matching server config found for host: " + host + " and port: " + std::to_string(port));
return nullptr;
+}
+
+GlobalConfig *ConfigManager::getGlobalConfig() const
+{
+ if (!initialized_)
+ {
+ throw std::runtime_error("ConfigManager is not initialized.");
+ }
+ return globalConfig_.get();
}
\ No newline at end of file
diff --git a/webserv/handler/Errorhandler.cpp b/webserv/handler/Errorhandler.cpp
index cbb0cae..c97ff61 100644
--- a/webserv/handler/Errorhandler.cpp
+++ b/webserv/handler/Errorhandler.cpp
@@ -1,3 +1,4 @@
+#include "webserv/config/ConfigManager.hpp"
#include
#include
#include // for StatusCode
@@ -30,11 +31,14 @@ std::string ErrorHandler::generateErrorPage(int statusCode, AConfig *config)
if (config != nullptr)
{
+ config = ConfigManager::getInstance().getGlobalConfig();
+ Log::info("Checking for custom error page for status code: " + std::to_string(statusCode));
std::string customPage = config->getErrorPage(statusCode);
if (!customPage.empty())
{
return getErrorPageFile(customPage);
}
+ Log::warning("No custom error page foundin config for status code: " + std::to_string(statusCode));
}
return generateDefaultErrorPage(statusCode);
}