Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core-amqp] improve error message on TypeError: sendRequest of undefined #13570

Merged
merged 6 commits into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdk/core/core-amqp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 2.1.0 (Unreleased)

- Fixes the bug reported in issue [13048](https://github.com/Azure/azure-sdk-for-js/issues/13048).
Now an informative error is thrown describing the circumstance that led to the error.
- Adds the ability to configure the `amqpHostname` and `port` that a `ConnectionContextBase` will use when connecting to a service.
The `host` field refers to the DNS host or IP address of the service, whereas the `amqpHostname`
is the fully qualified host name of the service. Normally `host` and `amqpHostname` will be the same.
Expand Down
6 changes: 5 additions & 1 deletion sdk/core/core-amqp/src/cbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ export class CbsClient {
tokenType: TokenType
): Promise<CbsResponse> {
try {
if (!this._cbsSenderReceiverLink) {
throw new Error("Attempted to negotiate a claim but the CBS link does not exist.");
}

const request: RheaMessage = {
body: token,
message_id: generate_uuid(),
Expand All @@ -201,7 +205,7 @@ export class CbsClient {
type: tokenType
}
};
const responseMessage = await this._cbsSenderReceiverLink!.sendRequest(request);
const responseMessage = await this._cbsSenderReceiverLink.sendRequest(request);
logger.verbose("[%s] The CBS response is: %O", this.connection.id, responseMessage);
return this._fromRheaMessageResponse(responseMessage);
} catch (err) {
Expand Down
27 changes: 27 additions & 0 deletions sdk/core/core-amqp/test/cbs.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { assert } from "chai";
import { Connection } from "rhea-promise";
import { stub } from "sinon";
import { CbsClient, TokenType } from "../src";

describe("CbsClient", function() {
const TEST_FAILURE = "Test failure";
describe("negotiateClaim", function() {
it("throws an error if the cbs link doesn't exist.", async function() {
const connectionStub = stub(new Connection()) as any;

const cbsClient = new CbsClient(connectionStub, "lock");
try {
await cbsClient.negotiateClaim("audience", "token", TokenType.CbsTokenTypeSas);
throw new Error(TEST_FAILURE);
} catch (err) {
assert.equal(
err.message,
"Attempted to negotiate a claim but the CBS link does not exist."
);
}
});
});
});