Impl: return error if param data is invalid

This commit is contained in:
2023-03-28 02:43:37 +11:00
parent a9ee266e34
commit eaec689577
+5 -1
View File
@@ -29,7 +29,11 @@ app.get("/api/:date?", (req, res) => {
res.json({ unix: date.getTime(), utc: date.toUTCString() });
} else {
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 {
const now = new Date();