exceptionfactory commented on code in PR #11876:
URL: https://github.com/apache/nifi/pull/11876#discussion_r4446305598
##########
nifi-extension-bundles/nifi-atlassian-bundle/nifi-atlassian-extensions/src/main/java/org/apache/nifi/atlassian/bitbucket/BitbucketRepositoryClient.java:
##########
@@ -1066,12 +1070,19 @@ public void close() throws IOException {
}
}
- private String getErrorMessage(HttpResponseEntity response) throws
FlowRegistryException {
+ private String getErrorMessage(final HttpResponseEntity response) throws
FlowRegistryException {
+ final byte[] responseBody;
+ try (InputStream body = response.body()) {
+ responseBody = body == null ? new byte[0] : body.readAllBytes();
+ } catch (final IOException e) {
+ throw new FlowRegistryException("Failed to read Bitbucket API
response with HTTP status %d".formatted(response.statusCode()), e);
+ }
+
final JsonNode jsonResponse;
try {
- jsonResponse = this.objectMapper.readTree(response.body());
- } catch (IOException e) {
- throw new FlowRegistryException("Could not parse response from
Bitbucket API", e);
+ jsonResponse = this.objectMapper.readTree(responseBody);
Review Comment:
If the `responseBody` is null or empty, it looks like the HTTP status code
would be lost in the return, should that be adjusted?
##########
nifi-extension-bundles/nifi-atlassian-bundle/nifi-atlassian-extensions/src/main/java/org/apache/nifi/atlassian/bitbucket/BitbucketRepositoryClient.java:
##########
@@ -1066,12 +1070,19 @@ public void close() throws IOException {
}
}
- private String getErrorMessage(HttpResponseEntity response) throws
FlowRegistryException {
+ private String getErrorMessage(final HttpResponseEntity response) throws
FlowRegistryException {
+ final byte[] responseBody;
+ try (InputStream body = response.body()) {
Review Comment:
To avoid the potential for very large responses being buffered into memory,
what about using something like the `LimitingInputStream` to wrap the response
body and enforcing the `512` cap?
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]