From bab5b2aafb911441eb4044b52ac82eb07ff0648a Mon Sep 17 00:00:00 2001 From: Donaldo S Date: Mon, 19 Sep 2016 15:38:02 -0700 Subject: [PATCH] Add 'else' statements to prevent 'Callback was already called' response during error --- api/routes/uploads.js | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/api/routes/uploads.js b/api/routes/uploads.js index 9040bfb..b909d24 100644 --- a/api/routes/uploads.js +++ b/api/routes/uploads.js @@ -254,10 +254,10 @@ server.post('/uploads', function(req, res, next) { if (err || result.statusCode != 200) { cb(err); - } - - cb(null); + } else { + cb(null); + } }); }, @@ -273,25 +273,25 @@ server.post('/uploads', function(req, res, next) { if (err) { cb(err); - } + } else { + + // if the location was found + if (location.features.length) { - // if the location was found - if (location.features.length) { + // extract coorindates + var coords = location.features[0].geometry.coordinates; + if (coords.length) { - // extract coorindates - var coords = location.features[0].geometry.coordinates; - if (coords.length) { + // assign to latitude and longitude in data object + data.longitude = coords[0]; + data.latitude = coords[1]; - // assign to latitude and longitude in data object - data.longitude = coords[0]; - data.latitude = coords[1]; + } } + cb(null) } - - cb(null) - }); }, @@ -304,13 +304,13 @@ server.post('/uploads', function(req, res, next) { if (err) { cb(err); - } + } else { - // use object assign to merge the object id - result = Object.assign({}, { id: result.insertId }, data); - - cb(null, result); + // use object assign to merge the object id + result = Object.assign({}, { id: result.insertId }, data); + cb(null, result); + } }); },