Skip to content

Commit

Permalink
Fix Management Bug (#22122)
Browse files Browse the repository at this point in the history
* Adding missing return statement.

* Using common logic for status codes.

* Adding isSuccessful.
  • Loading branch information
conniey authored Jun 8, 2021
1 parent 81e47a4 commit e2afc2c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,13 @@ private Mono<Void> 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();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ private <T> Mono<T> getProperties(Map<String, Object> properties, Class<T> 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)));
}
}));
});
}
Expand Down

0 comments on commit e2afc2c

Please sign in to comment.