From dd3175ae5a2a99ef690a9e4763f7abbd282d69e8 Mon Sep 17 00:00:00 2001 From: Arjun Patel Date: Sun, 30 Dec 2018 23:32:20 -0800 Subject: [PATCH] adding error if no physician found --- index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 9de0014..7816f26 100644 --- a/index.js +++ b/index.js @@ -59,8 +59,12 @@ app.get('/physicianloc', function (req, res) { var query = 'SELECT * FROM physicians WHERE LOWER(first_name)=?' + 'AND LOWER(middle_name)=? AND LOWER(last_name)=?'; connection.query(query, [first, middle, last], function (error, results, fields) { - if (error) throw error; - + if (error) console.log(error); + if (results.length === 0) { + return res.status(400).send({ + message: 'Physician Not Found!' + }); + } var result = res.status(200).send(results[0]); connection.release();