Handling http errors a bit more gracefully
This commit is contained in:
@@ -276,17 +276,17 @@ namespace daggy {
|
||||
auto response = HTTP_REQUEST(url, payload, method);
|
||||
|
||||
rj::Document doc;
|
||||
if (response.code == HTTPCode::Server_Error) {
|
||||
doc.SetObject();
|
||||
auto &alloc = doc.GetAllocator();
|
||||
doc.AddMember("error",
|
||||
rj::Value().SetString(response.body.c_str(),
|
||||
response.body.size(), alloc),
|
||||
alloc);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
checkRJParse(doc.Parse(response.body.c_str()));
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
doc.SetObject();
|
||||
auto &alloc = doc.GetAllocator();
|
||||
std::string message = (response.body.empty() ? e.what() : response.body);
|
||||
doc.AddMember(
|
||||
"error",
|
||||
rj::Value().SetString(message.c_str(), message.size(), alloc), alloc);
|
||||
}
|
||||
|
||||
return std::make_pair(response.code, std::move(doc));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user