Fix error handling in server examples

This commit is contained in:
Evgeniy
2017-07-20 08:12:09 -07:00
committed by Vinnie Falco
parent 0c0b2f2545
commit d5d8e2fcd2
2 changed files with 30 additions and 23 deletions
+16 -12
View File
@@ -172,33 +172,37 @@ private:
write(sock, res, ec);
if(ec)
break;
return;
}
resp_type res;
res.status = 200;
res.reason = "OK";
res.version = req.version;
res.headers.insert("Server", "http_sync_server");
res.headers.insert("Content-Type", mime_type(path));
res.body = path;
try
{
resp_type res;
res.status = 200;
res.reason = "OK";
res.version = req.version;
res.headers.insert("Server", "http_sync_server");
res.headers.insert("Content-Type", mime_type(path));
res.body = path;
prepare(res);
write(sock, res, ec);
if(ec)
break;
}
catch(std::exception const& e)
{
res = {};
response_v1<string_body> res;
res.status = 500;
res.reason = "Internal Error";
res.version = req.version;
res.headers.insert("Server", "http_sync_server");
res.headers.insert("Content-Type", "text/html");
res.body =
std::string{"An internal error occurred"} + e.what();
std::string{"An internal error occurred: "} + e.what();
prepare(res);
write(sock, res, ec);
if(ec)
break;
}
write(sock, res, ec);
if(ec)
break;
}
fail(id, ec);
}