Impl: return error if param data is invalid
This commit is contained in:
		
							parent
							
								
									a9ee266e34
								
							
						
					
					
						commit
						eaec689577
					
				
							
								
								
									
										4
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								index.js
									
									
									
									
									
								
							@ -29,8 +29,12 @@ app.get("/api/:date?", (req, res) => {
 | 
			
		||||
      res.json({ unix: date.getTime(), utc: date.toUTCString() });
 | 
			
		||||
    } else {
 | 
			
		||||
      const date = new Date(req.params.date);
 | 
			
		||||
      if (Number.isNaN(date.getTime())) {
 | 
			
		||||
        res.json({ error: "Invalid Date" });
 | 
			
		||||
      } else {
 | 
			
		||||
        res.json({ unix: date.getTime(), utc: date.toUTCString() });
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  } else {
 | 
			
		||||
    const now = new Date();
 | 
			
		||||
    res.json({ unix: now.getTime(), utc: now.toUTCString() });
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user