javascript - Why I am unable to catch URI error in decodeURIComponent() method -
i writing timestamp api freecodecamp project using node , express. works if request sent. request http://localhost:3000/x%y method decodeuricomponent throwing error. problem unable handle error.here code.. app.get('/:ts',function(req,res){
var reply; var timestamp = req.params.ts; if(timestamp){ if(number(timestamp)){ timestamp = timestamp * 1000; var d = new date(number(timestamp)); reply = { "unixtime": timestamp, "noramtime": d.getdate() + " " + months[d.getmonth()] + ", " +d.getfullyear() } } else{ try{ timestamp = decodeuricomponent(timestamp); console.log(1); if(timestamp){ var d = new date(timestamp).gettime(); if(!isnan(d)){ reply = { "unixtime": d/1000, "noramtime": timestamp } }else{ reply = { "unixtime": null, "noramtime": null } } }else{ reply = { "unixtime": null, "noramtime": null } } }catch(e){ res.sendstatus(400); } } }else{ reply = { "unixtime": null, "noramtime": null } } res.end(json.stringify(reply)); });
Comments
Post a Comment