Skip to content

Commit 1c70bc8

Browse files
Handle proton:io errors with meaningful error msg (#427)
* Handle proton:io errors with meaningful error msg * Use Proton-supplied message if present
1 parent 75b28c1 commit 1c70bc8

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

azure-eventhubs/src/main/java/com/microsoft/azure/eventhubs/impl/AmqpConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
public final class AmqpConstants {
1414

1515
public static final String APACHE = "apache.org";
16+
public static final String PROTON = "proton";
1617
public static final String VENDOR = "com.microsoft";
1718
public static final String AMQP_ANNOTATION_FORMAT = "amqp.annotation.%s >%s '%s'";
1819
public static final String OFFSET_ANNOTATION_NAME = "x-opt-offset";

azure-eventhubs/src/main/java/com/microsoft/azure/eventhubs/impl/ClientConstants.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public final class ClientConstants {
2020
public final static Symbol STORE_LOCK_LOST_ERROR = Symbol.getSymbol(AmqpConstants.VENDOR + ":store-lock-lost");
2121
public final static Symbol PUBLISHER_REVOKED_ERROR = Symbol.getSymbol(AmqpConstants.VENDOR + ":publisher-revoked");
2222
public final static Symbol TIMEOUT_ERROR = Symbol.getSymbol(AmqpConstants.VENDOR + ":timeout");
23+
public final static Symbol PROTON_IO_ERROR = Symbol.getSymbol(AmqpConstants.PROTON + ":io");
2324
public final static Symbol TRACKING_ID_PROPERTY = Symbol.getSymbol(AmqpConstants.VENDOR + ":tracking-id");
2425
public static final int MAX_MESSAGE_LENGTH_BYTES = 256 * 1024;
2526
public static final int MAX_FRAME_SIZE_BYTES = 64 * 1024;
@@ -76,6 +77,9 @@ public final class ClientConstants {
7677
public static final String TOKEN_AUDIENCE_FORMAT = "amqp://%s/%s";
7778
public static final String HTTPS_URI_FORMAT = "https://%s:%s";
7879
public static final int MAX_RECEIVER_NAME_LENGTH = 64;
80+
81+
public static final String COMMUNICATION_EXCEPTION_GENERIC_MESSAGE = "A communication error has occurred. " +
82+
"This may be due to an incorrect host name in your connection string or a problem with your network connection.";
7983

8084
/**
8185
* This is a constant defined to represent the start of a partition stream in EventHub.

azure-eventhubs/src/main/java/com/microsoft/azure/eventhubs/impl/ExceptionUtil.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ static Exception toException(ErrorCondition errorCondition) {
5555
return new EventHubException(true, new AmqpException(errorCondition));
5656
} else if (errorCondition.getCondition() == AmqpErrorCode.ResourceLimitExceeded) {
5757
return new QuotaExceededException(new AmqpException(errorCondition));
58+
} else if (errorCondition.getCondition() == ClientConstants.PROTON_IO_ERROR) {
59+
String message = ClientConstants.COMMUNICATION_EXCEPTION_GENERIC_MESSAGE;
60+
if (errorCondition.getDescription() != null) {
61+
message = errorCondition.getDescription();
62+
}
63+
return new CommunicationException(message, null);
5864
}
5965

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

0 commit comments

Comments
 (0)