From e2afc2c58a02f103c15260f55e2c2859e23e7925 Mon Sep 17 00:00:00 2001 From: Connie Yau Date: Mon, 7 Jun 2021 23:56:17 -0700 Subject: [PATCH] Fix Management Bug (#22122) * Adding missing return statement. * Using common logic for status codes. * Adding isSuccessful. --- .../amqp/implementation/ManagementChannel.java | 7 +++---- .../amqp/implementation/RequestResponseUtils.java | 4 ++++ .../implementation/ManagementChannel.java | 14 +++++++------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/ManagementChannel.java b/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/ManagementChannel.java index f469f879dede0..04145e4ece7be 100644 --- a/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/ManagementChannel.java +++ b/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/ManagementChannel.java @@ -116,14 +116,13 @@ private Mono isAuthorized() { .next() .switchIfEmpty(Mono.error(new AmqpException(false, "Did not get response from tokenManager: " + entityPath, getErrorContext()))) .handle((response, sink) -> { - if (response != AmqpResponseCode.ACCEPTED && response != AmqpResponseCode.OK) { + if (RequestResponseUtils.isSuccessful(response)) { + sink.complete(); + } else { final String message = String.format("User does not have authorization to perform operation " + "on entity [%s]. Response: [%s]", entityPath, response); sink.error(ExceptionUtil.amqpResponseCodeToException(response.getValue(), message, getErrorContext())); - - } else { - sink.complete(); } }); } diff --git a/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/RequestResponseUtils.java b/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/RequestResponseUtils.java index d61b8594b9de5..d0c2fead82a19 100644 --- a/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/RequestResponseUtils.java +++ b/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/RequestResponseUtils.java @@ -28,6 +28,10 @@ public class RequestResponseUtils { public static boolean isSuccessful(Message message) { final AmqpResponseCode statusCode = getStatusCode(message); + return isSuccessful(statusCode); + } + + public static boolean isSuccessful(AmqpResponseCode statusCode) { return statusCode == AmqpResponseCode.OK || statusCode == AmqpResponseCode.ACCEPTED; } diff --git a/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/implementation/ManagementChannel.java b/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/implementation/ManagementChannel.java index 9fd59529d17e4..254e37b16e662 100644 --- a/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/implementation/ManagementChannel.java +++ b/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/implementation/ManagementChannel.java @@ -162,14 +162,14 @@ private Mono getProperties(Map properties, Class respo .handle((message, sink) -> { if (RequestResponseUtils.isSuccessful(message)) { sink.next(messageSerializer.deserialize(message, responseType)); - } - - final AmqpResponseCode statusCode = RequestResponseUtils.getStatusCode(message); - final String statusDescription = RequestResponseUtils.getStatusDescription(message); - final Throwable error = ExceptionUtil.amqpResponseCodeToException(statusCode.getValue(), - statusDescription, channel.getErrorContext()); + } else { + final AmqpResponseCode statusCode = RequestResponseUtils.getStatusCode(message); + final String statusDescription = RequestResponseUtils.getStatusDescription(message); + final Throwable error = ExceptionUtil.amqpResponseCodeToException(statusCode.getValue(), + statusDescription, channel.getErrorContext()); - sink.error(logger.logExceptionAsWarning(Exceptions.propagate(error))); + sink.error(logger.logExceptionAsWarning(Exceptions.propagate(error))); + } })); }); }