Skip to content

Commit

Permalink
fix: dns resolution error format
Browse files Browse the repository at this point in the history
  • Loading branch information
saikumarrs committed Feb 8, 2024
1 parent 67dafb1 commit 3ce926f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/util/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check warning on line 35 in src/util/utils.js

View check run for this annotation

Codecov / codecov/patch

src/util/utils.js#L35

Added line #L35 was not covered by tests
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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/__tests__/user_transformation_fetch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3ce926f

Please sign in to comment.