From 3ce926f2a289f0390212057927e2c78e8045e802 Mon Sep 17 00:00:00 2001 From: Sai Kumar Battinoju Date: Thu, 8 Feb 2024 16:50:32 +0530 Subject: [PATCH] fix: dns resolution error format --- src/util/utils.js | 6 +++--- test/__tests__/user_transformation_fetch.test.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/util/utils.js b/src/util/utils.js index 0ba6008368..5d1d265143 100644 --- a/src/util/utils.js +++ b/src/util/utils.js @@ -26,20 +26,20 @@ const staticLookup = (transformerVersionId) => async (hostname, _, cb) => { transformerVersionId, error: 'true', }); - cb(null, `unable to resolve IP address for ${hostname}`, RECORD_TYPE_A); + cb(new Error(`unable to resolve IP address for ${hostname}`), null, RECORD_TYPE_A); return; } stats.timing('fetch_dns_resolve_time', resolveStartTime, { transformerVersionId }); if (ips.length === 0) { - cb(null, `resolved empty list of IP address for ${hostname}`, RECORD_TYPE_A); + cb(new Error(`resolved empty list of IP address for ${hostname}`), null, RECORD_TYPE_A); return; } // eslint-disable-next-line no-restricted-syntax for (const ip of ips) { if (ip.startsWith(LOCALHOST_OCTET)) { - cb(null, `cannot use ${ip} as IP address`, RECORD_TYPE_A); + cb(new Error(`cannot use ${ip} as IP address`), null, RECORD_TYPE_A); return; } } diff --git a/test/__tests__/user_transformation_fetch.test.js b/test/__tests__/user_transformation_fetch.test.js index e37b42ea1e..c9c7899888 100644 --- a/test/__tests__/user_transformation_fetch.test.js +++ b/test/__tests__/user_transformation_fetch.test.js @@ -149,7 +149,7 @@ describe("User transformation fetch tests", () => { } ` }; - const errMsg = "request to https://abc.xyz.com/dummyUrl failed, reason: Invalid IP address: unable to resolve IP address for abc.xyz.com"; + const errMsg = "request to https://abc.xyz.com/dummyUrl failed, reason: unable to resolve IP address for abc.xyz.com"; mockResolver.mockRejectedValue('invalid host'); const output = await userTransformHandler(inputData, versionId, [], trRevCode, true); @@ -305,7 +305,7 @@ describe("User transformation fetch tests", () => { } ` }; - const errMsg = "request to https://abc.xyz.com/dummyUrl failed, reason: Invalid IP address: cannot use 127.0.0.1 as IP address"; + const errMsg = "request to https://abc.xyz.com/dummyUrl failed, reason: cannot use 127.0.0.1 as IP address"; mockResolver.mockResolvedValue(['3.122.122.122', '127.0.0.1']); const output = await userTransformHandler(inputData, versionId, [], trRevCode, true);