Commit 001c561b authored by Mathieu Stefani's avatar Mathieu Stefani

The default handler now returns an HTTP 500 when an exception occurs

parent 493c8fe0
......@@ -449,26 +449,24 @@ Response::writeTo(Tcp::Peer& peer)
void
Handler::onInput(const char* buffer, size_t len, Tcp::Peer& peer) {
auto& parser = getParser(peer);
if (!parser.feed(buffer, len)) {
cout << "Could not feed parser bro" << endl;
}
else {
try {
auto state = parser.parse();
if (state == Private::Parser::State::Done) {
onRequest(parser.request, peer);
parser.reset();
}
} catch (const HttpError &err) {
Response response(err.code(), err.reason());
response.writeTo(peer);
try {
auto& parser = getParser(peer);
if (!parser.feed(buffer, len)) {
throw HttpError(Code::Request_Entity_Too_Large, "Request exceeded maximum buffer size");
}
catch (const std::exception& e) {
Response response(Code::Internal_Server_Error, e.what());
response.writeTo(peer);
auto state = parser.parse();
if (state == Private::Parser::State::Done) {
onRequest(parser.request, peer);
parser.reset();
}
} catch (const HttpError &err) {
Response response(err.code(), err.reason());
response.writeTo(peer);
}
catch (const std::exception& e) {
Response response(Code::Internal_Server_Error, e.what());
response.writeTo(peer);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment