Impl: return error if param data is invalid

This commit is contained in:
Manish 2023-03-28 02:43:37 +11:00
parent a9ee266e34
commit eaec689577

View File

@ -29,7 +29,11 @@ app.get("/api/:date?", (req, res) => {
res.json({ unix: date.getTime(), utc: date.toUTCString() }); res.json({ unix: date.getTime(), utc: date.toUTCString() });
} else { } else {
const date = new Date(req.params.date); const date = new Date(req.params.date);
res.json({ unix: date.getTime(), utc: date.toUTCString() }); if (Number.isNaN(date.getTime())) {
res.json({ error: "Invalid Date" });
} else {
res.json({ unix: date.getTime(), utc: date.toUTCString() });
}
} }
} else { } else {
const now = new Date(); const now = new Date();