Skip to content

Commit

Permalink
[Event Hubs] [Service Bus] Added event handlers for error and `prot…
Browse files Browse the repository at this point in the history
…ocolError` events on the connection object. (#4323)
  • Loading branch information
ShivangiReja authored and ramya-rao-a committed Jul 16, 2019
1 parent e1e7386 commit ef2b4e6
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
36 changes: 36 additions & 0 deletions sdk/eventhub/event-hubs/src/connectionContext.ts
Expand Up @@ -237,9 +237,45 @@ export namespace ConnectionContext {
}
};

const protocolError: OnAmqpEvent = async (context: EventContext) => {
if (context.connection && context.connection.error) {
log.error(
"[%s] Error (context.connection.error) occurred on the amqp connection: %O",
connectionContext.connection.id,
context.connection && context.connection.error
);
}
if (context.error) {
log.error(
"[%s] Error (context.error) occurred on the amqp connection: %O",
connectionContext.connection.id,
context.error
);
}
};

const error: OnAmqpEvent = async (context: EventContext) => {
if (context.connection && context.connection.error) {
log.error(
"[%s] Error (context.connection.error) occurred on the amqp connection: %O",
connectionContext.connection.id,
context.connection && context.connection.error
);
}
if (context.error) {
log.error(
"[%s] Error (context.error) occurred on the amqp connection: %O",
connectionContext.connection.id,
context.error
);
}
};

// Add listeners on the connection object.
connectionContext.connection.on(ConnectionEvents.connectionOpen, onConnectionOpen);
connectionContext.connection.on(ConnectionEvents.disconnected, disconnected);
connectionContext.connection.on(ConnectionEvents.protocolError, protocolError);
connectionContext.connection.on(ConnectionEvents.error, error);

log.context("[%s] Created connection context successfully.", connectionContext.connectionId);
return connectionContext;
Expand Down
1 change: 1 addition & 0 deletions sdk/servicebus/service-bus/changelog.md
@@ -1,6 +1,7 @@
# 2019-07-09 1.0.3

- Update `amqp-common` dependency version to 1.0.0-preview.6. This includes fix for the [bug 3971](https://github.com/Azure/azure-sdk-for-js/issues/3971) where the token audience in the credential created during [MSI based login](https://www.npmjs.com/package/@azure/ms-rest-nodeauth/v/2.0.2#msi-managed-service-identity-based-login-from-a-virtual-machine-created-in-azure) was being ignored. [PR 4146](https://github.com/Azure/azure-sdk-for-js/pull/4146)
- Added event handlers for `error` and `protocolError` events on the connection object to avoid the case of unhandled exceptions like [bug 4136](https://github.com/Azure/azure-sdk-for-js/issues/4136)

# 2019-05-21 1.0.2

Expand Down
36 changes: 36 additions & 0 deletions sdk/servicebus/service-bus/src/connectionContext.ts
Expand Up @@ -146,9 +146,45 @@ export namespace ConnectionContext {
}
};

const protocolError: OnAmqpEvent = async (context: EventContext) => {
if (context.connection && context.connection.error) {
log.error(
"[%s] Error (context.connection.error) occurred on the amqp connection: %O",
connectionContext.connection.id,
context.connection && context.connection.error
);
}
if (context.error) {
log.error(
"[%s] Error (context.error) occurred on the amqp connection: %O",
connectionContext.connection.id,
context.error
);
}
};

const error: OnAmqpEvent = async (context: EventContext) => {
if (context.connection && context.connection.error) {
log.error(
"[%s] Error (context.connection.error) occurred on the amqp connection: %O",
connectionContext.connection.id,
context.connection && context.connection.error
);
}
if (context.error) {
log.error(
"[%s] Error (context.error) occurred on the amqp connection: %O",
connectionContext.connection.id,
context.error
);
}
};

// Add listeners on the connection object.
connectionContext.connection.on(ConnectionEvents.connectionOpen, onConnectionOpen);
connectionContext.connection.on(ConnectionEvents.disconnected, disconnected);
connectionContext.connection.on(ConnectionEvents.protocolError, protocolError);
connectionContext.connection.on(ConnectionEvents.error, error);

log.connectionCtxt(
"[%s] Created connection context successfully.",
Expand Down

0 comments on commit ef2b4e6

Please sign in to comment.