From 008b8f2360c7a003f2840ac7bb5b31d32ec4c006 Mon Sep 17 00:00:00 2001 From: Francesco Esposito <33671357+frab1t@users.noreply.github.com> Date: Fri, 22 Feb 2019 10:09:38 +0100 Subject: [PATCH] implements status code 404 in index --- controllers/deviceController.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/controllers/deviceController.js b/controllers/deviceController.js index 9912562..a97342c 100644 --- a/controllers/deviceController.js +++ b/controllers/deviceController.js @@ -11,11 +11,15 @@ function index(req, res) { return res.json(device); }); } else { - Device.get((err, devices) => { + Device.find({}, (err, devices) => { if (err) { logger.logError(`index: ${err}`); return res.status(500).send(); } + + if (devices.length === 0) { + return res.status(404).send(); + } return res.json(devices); }); }