diff --git a/middleware/geocodeJSON.js b/middleware/geocodeJSON.js index a5e136b0..e7948cec 100644 --- a/middleware/geocodeJSON.js +++ b/middleware/geocodeJSON.js @@ -14,6 +14,11 @@ function setup(peliasConfig) { function convertToGeocodeJSON(peliasConfig, req, next) { + // do nothing if no result data set + if (!req.results || !req.results.data) { + return next(); + } + req.results.geojson = { geocoding: {} }; // REQUIRED. A semver.org compliant version number. Describes the version of diff --git a/middleware/renamePlacenames.js b/middleware/renamePlacenames.js index 9e24fc8f..6b27d2fc 100644 --- a/middleware/renamePlacenames.js +++ b/middleware/renamePlacenames.js @@ -32,7 +32,7 @@ function setup() { function renamePlacenames(req, res, next) { // do nothing if no result data set - if (!req.results.data) { + if (!req.results || !req.results.data) { return next(); } diff --git a/middleware/sendJSON.js b/middleware/sendJSON.js index 8ab0bc88..1fd21a4c 100644 --- a/middleware/sendJSON.js +++ b/middleware/sendJSON.js @@ -1,4 +1,10 @@ -function sendJSONResponse(req, res) { +function sendJSONResponse(req, res, next) { + + // do nothing if no result data set + if (!req.results || !req.results.geojson) { + return next(); + } + // respond return res.status(200).json(req.results.geojson); }