Skip to content

Commit 6e6fb6a

Browse files
[App Config] Better error message for AppConfigClient with invalid connection strings (#18356)
* better error message for AppConfigClient * changelog * (connectionStringOrEndpoint || "").match * connectionStringOrEndpoint?.match
1 parent b4d48e4 commit 6e6fb6a

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

sdk/appconfiguration/app-configuration/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
### Other Changes
1515

16+
- Throws a better error message if provided invalid connection strings such as `undefined` to the `AppConfigurationClient` constructor. [#18356](https://github.com/Azure/azure-sdk-for-js/pull/18356)
17+
1618
## 1.3.0 (2021-07-26)
1719

1820
### Features Added

sdk/appconfiguration/app-configuration/recordings/node/authentication/recording_invalid_connection_string_gives_a_decent_error_message.js

-5
This file was deleted.

sdk/appconfiguration/app-configuration/src/appConfigurationClient.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,7 @@ export class AppConfigurationClient {
162162
appConfigEndpoint = connectionStringOrEndpoint;
163163
} else {
164164
appConfigOptions = (tokenCredentialOrOptions as InternalAppConfigurationClientOptions) || {};
165-
166-
const regexMatch = connectionStringOrEndpoint.match(ConnectionStringRegex);
167-
165+
const regexMatch = connectionStringOrEndpoint?.match(ConnectionStringRegex);
168166
if (regexMatch) {
169167
appConfigCredential = new AppConfigCredential(regexMatch[2], regexMatch[3]);
170168
appConfigEndpoint = regexMatch[1];

sdk/appconfiguration/app-configuration/test/public/auth.spec.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ describe("Authentication", () => {
2323
afterEach(async function() {
2424
await recorder.stop();
2525
});
26-
27-
it("invalid connection string gives a decent error message", () => {
28-
assert.throws(
29-
() => new AppConfigurationClient("an invalid connection string"),
30-
/Invalid connection string\. Valid connection strings should match the regex 'Endpoint=\(\.\*\);Id=\(\.\*\);Secret=\(\.\*\)'/
31-
);
32-
});
33-
3426
it("token authentication works", async function() {
3527
const client = new AppConfigurationClient(
3628
credsAndEndpoint.endpoint,
@@ -45,3 +37,19 @@ describe("Authentication", () => {
4537
});
4638
});
4739
});
40+
41+
describe("AppConfigurationClient constructor error cases", () => {
42+
it("invalid connection string gives a decent error message", () => {
43+
assert.throws(
44+
() => new AppConfigurationClient("an invalid connection string"),
45+
/Invalid connection string\. Valid connection strings should match the regex 'Endpoint=\(\.\*\);Id=\(\.\*\);Secret=\(\.\*\)'/
46+
);
47+
});
48+
49+
it("undefined connection string gives a decent error message", () => {
50+
assert.throws(
51+
() => new AppConfigurationClient(undefined as any),
52+
/Invalid connection string\. Valid connection strings should match the regex 'Endpoint=\(\.\*\);Id=\(\.\*\);Secret=\(\.\*\)'/
53+
);
54+
});
55+
});

0 commit comments

Comments
 (0)