Skip to content

Commit c16e3d9

Browse files
committed
DM-53152: Fixed incorrect handling of responses from REST services
1 parent c68c7f4 commit c16e3d9

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/czar/HttpCzarIngestModule.cc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,21 @@ json HttpCzarIngestModule::_ingestData() {
186186
// Process workers' responses.
187187
map<string, string> errors;
188188
for (auto const& [workerId, req] : workerRequests) {
189-
if (req->responseCode() != qhttp::STATUS_OK) {
190-
errors[workerId] = "http_code: " + to_string(req->responseCode());
189+
string error;
190+
if (req->state() == http::AsyncReq::State::FINISHED) {
191+
if (req->responseCode() != qhttp::STATUS_OK) {
192+
errors[workerId] =
193+
"request state: " + http::AsyncReq::state2str(req->state()) +
194+
", error: " + req->errorMessage() +
195+
", http_code: " + to_string(req->responseCode());
196+
continue;
197+
}
198+
} else {
199+
errors[workerId] = "request state: " + http::AsyncReq::state2str(req->state()) +
200+
", error: " + req->errorMessage();
191201
continue;
192202
}
203+
193204
json resp;
194205
try {
195206
resp = json::parse(req->responseBody());

src/czar/HttpCzarIngestModuleBase.cc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,21 @@ json HttpCzarIngestModuleBase::_request(http::Method method, string const& url,
310310
auto const request = _asyncRequest(method, url, data);
311311
request->start();
312312
request->wait();
313-
if (request->responseCode() != qhttp::STATUS_OK) {
314-
throw http::Error(__func__, "http_code: " + to_string(request->responseCode()), errorExt);
313+
if (request->state() == http::AsyncReq::State::FINISHED) {
314+
if (request->responseCode() != qhttp::STATUS_OK) {
315+
throw http::Error(__func__,
316+
"request state: " + http::AsyncReq::state2str(request->state()) +
317+
", error: " + request->errorMessage() +
318+
", http_code: " + to_string(request->responseCode()),
319+
errorExt);
320+
}
321+
} else {
322+
throw http::Error(__func__,
323+
"request state: " + http::AsyncReq::state2str(request->state()) +
324+
", error: " + request->errorMessage(),
325+
errorExt);
315326
}
327+
316328
json response;
317329
try {
318330
response = json::parse(request->responseBody());

0 commit comments

Comments
 (0)