refactor(Client): improve error handling in request method and clean up includes

This commit is contained in:
Quinten 2025-10-14 19:10:27 +02:00
parent 68ea191460
commit 9b7f50cc04

View File

@ -1,5 +1,4 @@
#include <webserv/client/Client.hpp> #include <webserv/client/Client.hpp>
#include <webserv/http/HttpHeaders.hpp> // for HttpHeaders #include <webserv/http/HttpHeaders.hpp> // for HttpHeaders
#include <webserv/log/Log.hpp> // for Log, LOCATION #include <webserv/log/Log.hpp> // for Log, LOCATION
#include <webserv/router/Router.hpp> // for Router #include <webserv/router/Router.hpp> // for Router
@ -7,6 +6,7 @@
#include <webserv/socket/ClientSocket.hpp> // for Socket #include <webserv/socket/ClientSocket.hpp> // for Socket
#include <cstdint> // for uint8_t #include <cstdint> // for uint8_t
#include <exception>
#include <functional> // for ref, reference_wrapper #include <functional> // for ref, reference_wrapper
#include <map> // for map #include <map> // for map
#include <string> // for basic_string, to_string, operator+, operator<=> #include <string> // for basic_string, to_string, operator+, operator<=>
@ -50,11 +50,11 @@ void Client::request()
if (bytesRead < 0) if (bytesRead < 0)
{ {
Log::error("Read error"); Log::error("Read error");
return; throw std::runtime_error("Read error");
} }
if (bytesRead == 0) if (bytesRead == 0)
{ {
Log::info("Client closed connection, fd: " + std::to_string(client_socket_->getFd())); // TODO weird Log::info("Client closed connection, fd: " + std::to_string(client_socket_->getFd()));
server_.disconnect(*this); // CRITICAL: RETURN IMMEDIATELY server_.disconnect(*this); // CRITICAL: RETURN IMMEDIATELY
return; return;
} }