kamilwu commented on a change in pull request #12102:
URL: https://github.com/apache/beam/pull/12102#discussion_r446173940
##########
File path:
sdks/java/testing/test-utils/src/main/java/org/apache/beam/sdk/testutils/publishing/InfluxDBPublisher.java
##########
@@ -146,16 +157,29 @@ private static HttpPost providePOSTRequest(final
InfluxDBSettings settings) {
private static void executeWithVerification(
final HttpPost postRequest, final HttpClientBuilder builder) throws
IOException {
try (final CloseableHttpResponse response =
builder.build().execute(postRequest)) {
- is2xx(response.getStatusLine().getStatusCode());
+ is2xx(response);
}
}
- private static void is2xx(final int code) throws IOException {
+ private static void is2xx(final HttpResponse response) throws IOException {
+ final int code = response.getStatusLine().getStatusCode();
if (code < 200 || code >= 300) {
- throw new IOException("Response code: " + code);
+ throw new IOException(
+ "Response code: " + code + ". Reason: " +
getErrorMessage(response.getEntity()));
}
}
+ private static String getErrorMessage(final HttpEntity entity) throws
IOException {
+ final Header encodingHeader = entity.getContentEncoding();
Review comment:
If you want to make it even more secure and resilient, you can check
what's the value of `Content-Type` header. For JSON, it must be
`application/json`. Some HTTP libraries has convenient methods for doing that.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]