promisify the resolve method to pass the error to the middleware and updat test cases accordingly

This commit is contained in:
om-3004 committed 2024-10-17 11:06:46 +05:30
1 parent 7ec5e64f6f
commit 0f763e7913
2 files changed
+14 -16

No files matched your search

+10 -10
View File
@@ -276,18 +276,18 @@ const checkEndpointResolution = async (req, res, next) => {
try {
let { monitorURL } = req.query;
monitorURL = new URL(monitorURL);
dns.resolve(monitorURL.hostname, (error) => {
if (error) {
return res.status(400).json({
success: false,
msg: `DNS resolution failed`,
});
}
return res.status(200).json({
success: true,
msg: `URL resolved successfully`,
await new Promise((resolve, reject) => {
dns.resolve(monitorURL.hostname, (error) => {
if (error) {
reject(error);
}
resolve();
});
});
return res.status(200).json({
success: true,
msg: `URL resolved successfully`,
});
} catch (error) {
next(handleError(error, SERVICE_NAME, "checkEndpointResolution"));
}