Skip to content

Commit

Permalink
[Service Bus] Improve err msg when failing to senders and receivers (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a authored Aug 5, 2020
1 parent 728219c commit 6512a65
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
6 changes: 6 additions & 0 deletions sdk/servicebus/service-bus/src/core/messageReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,12 @@ export class MessageReceiver extends LinkEntity {
this.name,
err
);

// Fix the unhelpful error messages for the OperationTimeoutError that comes from `rhea-promise`.
if ((err as MessagingError).code === "OperationTimeoutError") {
err.message = "Failed to create a receiver within allocated time and retry attempts.";
}

throw err;
}
}
Expand Down
4 changes: 4 additions & 0 deletions sdk/servicebus/service-bus/src/core/messageSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,10 @@ export class MessageSender extends LinkEntity {
this.name,
err
);
// Fix the unhelpful error messages for the OperationTimeoutError that comes from `rhea-promise`.
if ((err as MessagingError).code === "OperationTimeoutError") {
err.message = "Failed to create a sender within allocated time and retry attempts.";
}
throw err;
} finally {
this.isConnecting = false;
Expand Down
13 changes: 11 additions & 2 deletions sdk/servicebus/service-bus/src/session/messageSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,11 @@ export class MessageSession extends LinkEntity {
if (this.providedSessionId == null && receivedSessionId == null) {
// Ideally this code path should never be reached as `MessageSession.createReceiver()` should fail instead
// TODO: https://github.com/Azure/azure-sdk-for-js/issues/9775 to figure out why this code path indeed gets hit.
errorMessage = `No unlocked sessions were available`;
errorMessage = `Failed to create a receiver. No unlocked sessions available.`;
} else if (this.providedSessionId != null && receivedSessionId !== this.providedSessionId) {
// This code path is reached if the session is already locked by another receiver.
// TODO: Check why the service would not throw an error or just timeout instead of giving a misleading successful receiver
errorMessage = `Failed to get a lock on the session ${this.providedSessionId}`;
errorMessage = `Failed to create a receiver for the requested session '${this.providedSessionId}'. It may be locked by another receiver.`;
}

if (errorMessage) {
Expand Down Expand Up @@ -398,6 +398,15 @@ export class MessageSession extends LinkEntity {
this.name,
errObj
);

// Fix the unhelpful error messages for the OperationTimeoutError that comes from `rhea-promise`.
if ((errObj as MessagingError).code === "OperationTimeoutError") {
if (this.providedSessionId) {
errObj.message = `Failed to create a receiver for the requested session '${this.providedSessionId}' within allocated time and retry attempts.`;
} else {
errObj.message = "Failed to create a receiver within allocated time and retry attempts.";
}
}
throw errObj;
}
}
Expand Down

0 comments on commit 6512a65

Please sign in to comment.