Skip to content

Commit 24c472e

Browse files
committed
Log broker response body when management request fails
1 parent b4948f0 commit 24c472e

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/main/java/com/rabbitmq/client/amqp/impl/AmqpManagement.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -461,12 +461,22 @@ private static void checkResponse(
461461
if (responseCode == CODE_404) {
462462
throw new AmqpException.AmqpEntityDoesNotExistException("Entity does not exist");
463463
} else {
464-
throw new AmqpException(
465-
"Unexpected response code: %d instead of %s",
466-
responseCode,
467-
IntStream.of(expectedResponseCodes)
468-
.mapToObj(String::valueOf)
469-
.collect(Collectors.joining(", ")));
464+
String message =
465+
String.format(
466+
"Unexpected response code: %d instead of %s",
467+
responseCode,
468+
IntStream.of(expectedResponseCodes)
469+
.mapToObj(String::valueOf)
470+
.collect(Collectors.joining(", ")));
471+
try {
472+
LOGGER.info(
473+
"Management request failed: '{}'. Response body: '{}'",
474+
message,
475+
request.responseMessage().body());
476+
} catch (Exception e) {
477+
LOGGER.info("Could not get management request body: {}", e.getMessage());
478+
}
479+
throw new AmqpException(message);
470480
}
471481
}
472482
}

0 commit comments

Comments
 (0)