diff --git a/packages/nodejs/.changesets/standardize-diagnose-validation-error-message.md b/packages/nodejs/.changesets/standardize-diagnose-validation-error-message.md new file mode 100644 index 00000000..6bee5784 --- /dev/null +++ b/packages/nodejs/.changesets/standardize-diagnose-validation-error-message.md @@ -0,0 +1,5 @@ +--- +bump: "patch" +--- + +Standardize diagnose validation failure message. Explain the diagnose request failed and why. diff --git a/packages/nodejs/src/diagnose.ts b/packages/nodejs/src/diagnose.ts index 6b83dfe3..e5944fbf 100644 --- a/packages/nodejs/src/diagnose.ts +++ b/packages/nodejs/src/diagnose.ts @@ -112,21 +112,27 @@ export class DiagnoseTool { private async validatePushApiKey() { return new Promise((resolve, reject) => { const config = this.#config.data - const params = new URLSearchParams({ api_key: config["apiKey"] }) + const params = new URLSearchParams({ + api_key: config["apiKey"] || "", + name: config["name"] || "", + environment: config["environment"] || "", + hostname: config["hostname"] || "" + }) const url = new URL(`/1/auth?${params.toString()}`, config["endpoint"]) const options = { method: "POST" } - const request = https.request(url, options, function (response) { + const requestModule = url.protocol == "http:" ? http : https + const request = requestModule.request(url, options, function (response) { const status = response.statusCode if (status === 200) { resolve("valid") } else if (status === 401) { reject("invalid") } else { - reject(`Failed with status ${status}`) + reject(`Failed to validate: status ${status}`) } }) - request.write("{}") // Send empty JSON body + request.write("") // Send empty body request.end() }) } diff --git a/test/integration/diagnose b/test/integration/diagnose index 16b9d33b..14db1144 160000 --- a/test/integration/diagnose +++ b/test/integration/diagnose @@ -1 +1 @@ -Subproject commit 16b9d33b60e128b19fabef0500ed36741eac8f1b +Subproject commit 14db1144fba87597be546aa6a8400c5299f5dddb