Skip to content

Commit

Permalink
Handle proton:io errors with meaningful error msg (Azure#427)
Browse files Browse the repository at this point in the history
* Handle proton:io errors with meaningful error msg

* Use Proton-supplied message if present
  • Loading branch information
JamesBirdsall authored Jan 29, 2019
1 parent 3ddd268 commit 120231b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public final class AmqpConstants {

public static final String APACHE = "apache.org";
public static final String PROTON = "proton";
public static final String VENDOR = "com.microsoft";
public static final String AMQP_ANNOTATION_FORMAT = "amqp.annotation.%s >%s '%s'";
public static final String OFFSET_ANNOTATION_NAME = "x-opt-offset";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public final class ClientConstants {
public final static Symbol STORE_LOCK_LOST_ERROR = Symbol.getSymbol(AmqpConstants.VENDOR + ":store-lock-lost");
public final static Symbol PUBLISHER_REVOKED_ERROR = Symbol.getSymbol(AmqpConstants.VENDOR + ":publisher-revoked");
public final static Symbol TIMEOUT_ERROR = Symbol.getSymbol(AmqpConstants.VENDOR + ":timeout");
public final static Symbol PROTON_IO_ERROR = Symbol.getSymbol(AmqpConstants.PROTON + ":io");
public final static Symbol TRACKING_ID_PROPERTY = Symbol.getSymbol(AmqpConstants.VENDOR + ":tracking-id");
public static final int MAX_MESSAGE_LENGTH_BYTES = 256 * 1024;
public static final int MAX_FRAME_SIZE_BYTES = 64 * 1024;
Expand Down Expand Up @@ -76,6 +77,9 @@ public final class ClientConstants {
public static final String TOKEN_AUDIENCE_FORMAT = "amqp://%s/%s";
public static final String HTTPS_URI_FORMAT = "https://%s:%s";
public static final int MAX_RECEIVER_NAME_LENGTH = 64;

public static final String COMMUNICATION_EXCEPTION_GENERIC_MESSAGE = "A communication error has occurred. " +
"This may be due to an incorrect host name in your connection string or a problem with your network connection.";

/**
* This is a constant defined to represent the start of a partition stream in EventHub.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ static Exception toException(ErrorCondition errorCondition) {
return new EventHubException(true, new AmqpException(errorCondition));
} else if (errorCondition.getCondition() == AmqpErrorCode.ResourceLimitExceeded) {
return new QuotaExceededException(new AmqpException(errorCondition));
} else if (errorCondition.getCondition() == ClientConstants.PROTON_IO_ERROR) {
String message = ClientConstants.COMMUNICATION_EXCEPTION_GENERIC_MESSAGE;
if (errorCondition.getDescription() != null) {
message = errorCondition.getDescription();
}
return new CommunicationException(message, null);
}

return new EventHubException(ClientConstants.DEFAULT_IS_TRANSIENT, errorCondition.getDescription());
Expand Down

0 comments on commit 120231b

Please sign in to comment.