i’m working on url shortener project. here i’m throwing an error if there is an error in dns.lookup
method. but it crashes my app instead of going to catch block.
here is my app on glitch https://fcc-url-shortener-gskumawat.glitch.me/
app.post('/api/shorturl/new', async function(req, res){
try{
let {host} = await new URL(req.body.url);
dns.lookup(host, function(err, family, address){
if(err){
throw Error('Invalid Url');
};
});
res.redirect('/');
}
catch(err){
return res.json({
error: err.message
})
}
})