From 929ab14a219c29c16eab27581f58880ce546e844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=BCller?= Date: Sun, 18 Oct 2015 18:49:03 +0200 Subject: [PATCH] deprecated link resolution crash caught --- server.js | 5 ++--- src/storage.js | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index c62c12c..6fe573f 100644 --- a/server.js +++ b/server.js @@ -53,9 +53,8 @@ app.post('/note', function (req, res) { }); app.get("/:year/:month/:day/:title", function (req, res) { - var P = req.params; - storage.getNoteId(P.year + "/" + P.month + "/" + P.day + "/" + P.title) - .then(id => res.redirect("/" + id)); + var P = req.params, url = P.year + "/" + P.month + "/" + P.day + "/" + P.title; + storage.getNoteId(url).then(note => note ? res.redirect("/" + id) : notFound(res)); }); app.get(/\/([a-z0-9]+\/edit)/, function (req, res) { diff --git a/src/storage.js b/src/storage.js index 6be8dc0..a6cde6e 100644 --- a/src/storage.js +++ b/src/storage.js @@ -28,7 +28,7 @@ module.exports.getNoteId = deprecatedId => { console.log("resolving deprecated Id", deprecatedId); return Note.findOne({ where: { deprecatedId: deprecatedId } - }).then(note => note.id); + }); } var generateId = () => [1, 1, 1, 1, 1]