From cbdbaa4276e97bfb1d187d6ccb6fb0904a0b749c Mon Sep 17 00:00:00 2001 From: Andi Pieper Date: Mon, 5 Aug 2024 11:48:00 +0200 Subject: [PATCH 1/3] feat(api): generic error messages --- src/api/errors.js | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/api/errors.js b/src/api/errors.js index c07f4e6..6b37e84 100644 --- a/src/api/errors.js +++ b/src/api/errors.js @@ -57,20 +57,8 @@ export class InvalidHostNameLookupError extends AppError { * @param {string} hostname */ constructor(hostname) { - super(`${hostname} can not be resolved`); + super(`The host name cannot be resolved`); this.name = "invalid-hostname-lookup"; this.statusCode = STATUS_CODES.unprocessableEntity; } } - -export class RescanTooSoonError extends AppError { - /** - * - * @param {string} hostname - */ - constructor(hostname) { - super(`${hostname} is on temporary cooldown'`); - this.name = "rescan-attempt-too-soon"; - this.statusCode = STATUS_CODES.badRequest; - } -} From 4d8efb369ceee62e545c94d8449e8b669500e88a Mon Sep 17 00:00:00 2001 From: Andi Pieper Date: Mon, 5 Aug 2024 11:49:21 +0200 Subject: [PATCH 2/3] feat(api): generic error messages --- test/apiv2.test.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/apiv2.test.js b/test/apiv2.test.js index 9343412..4c556b7 100644 --- a/test/apiv2.test.js +++ b/test/apiv2.test.js @@ -213,10 +213,7 @@ describeOrSkip("API V2", function () { const r = JSON.parse(response.body); assert.isObject(r); assert.equal(r.error, "invalid-hostname-lookup"); - assert.equal( - r.message, - "www.somethingorother1234.mozilla.net can not be resolved" - ); + assert.equal(r.message, "The host name cannot be resolved"); }).timeout(6000); it("responds to GET /analyze of an ip address", async function () { From 285878cc3a4191d9e960aabd582b98eddf7cf5c2 Mon Sep 17 00:00:00 2001 From: Andi Pieper Date: Mon, 5 Aug 2024 14:08:31 +0200 Subject: [PATCH 3/3] feat(api): generic error messages, improved. use `error.name` on the frontend for glean --- src/api/errors.js | 2 +- test/apiv2.test.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/api/errors.js b/src/api/errors.js index 6b37e84..4787007 100644 --- a/src/api/errors.js +++ b/src/api/errors.js @@ -57,7 +57,7 @@ export class InvalidHostNameLookupError extends AppError { * @param {string} hostname */ constructor(hostname) { - super(`The host name cannot be resolved`); + super(`${hostname} cannot be resolved`); this.name = "invalid-hostname-lookup"; this.statusCode = STATUS_CODES.unprocessableEntity; } diff --git a/test/apiv2.test.js b/test/apiv2.test.js index 4c556b7..9a05541 100644 --- a/test/apiv2.test.js +++ b/test/apiv2.test.js @@ -213,7 +213,10 @@ describeOrSkip("API V2", function () { const r = JSON.parse(response.body); assert.isObject(r); assert.equal(r.error, "invalid-hostname-lookup"); - assert.equal(r.message, "The host name cannot be resolved"); + assert.equal( + r.message, + "www.somethingorother1234.mozilla.net cannot be resolved" + ); }).timeout(6000); it("responds to GET /analyze of an ip address", async function () {