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

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -