Impl: return error if param data is invalid
This commit is contained in:
parent
a9ee266e34
commit
eaec689577
6
index.js
6
index.js
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user