Describe the bug
When OkHttpClient sends snowplow payload and it fails with any code like 404, then the return code is always = -1.
It only sets to actual value, when the response is successful.
To Reproduce
OkHttpClientAdapter:
public int doPost(String url, String payload) {
int returnValue = -1;
RequestBody body = RequestBody.create(payload, JSON);
Request request = new Request.Builder()
.url(url)
.addHeader("Content-Type", Constants.POST_CONTENT_TYPE)
.post(body)
.build();
try (Response response = httpClient.newCall(request).execute()) {
if (!response.isSuccessful()) {
LOGGER.error("OkHttpClient POST Request failed: {}", response);
} else {
returnValue = response.code();
}
} catch (IOException e) {
LOGGER.error("OkHttpClient POST Request failed: {}", e.getMessage());
}
return returnValue;
}
Expected behavior
in the block
if (!response.isSuccessful()) {
}
there should be also returnValue = response.code(); So for example retry etc can pick up the code and evaluate the value.
better remove the else block like this:
Describe the bug When OkHttpClient sends snowplow payload and it fails with any code like 404, then the return code is always = -1.
It only sets to actual value, when the response is successful.
To Reproduce OkHttpClientAdapter:
Expected behavior in the block
if (!response.isSuccessful()) { } there should be also returnValue = response.code(); So for example retry etc can pick up the code and evaluate the value. better remove the else block like this:
Same applies for doGet() method Screenshots If applicable, add screenshots to help explain your problem.
Environment (please complete the following information):
Additional context Add any other context about the problem here.