Browse Source

Add checks for presence of results

pull/210/head
Diana Shkolnikov 9 years ago
parent
commit
0f2ff935ec
  1. 5
      middleware/geocodeJSON.js
  2. 2
      middleware/renamePlacenames.js
  3. 8
      middleware/sendJSON.js

5
middleware/geocodeJSON.js

@ -14,6 +14,11 @@ function setup(peliasConfig) {
function convertToGeocodeJSON(peliasConfig, req, next) { function convertToGeocodeJSON(peliasConfig, req, next) {
// do nothing if no result data set
if (!req.results || !req.results.data) {
return next();
}
req.results.geojson = { geocoding: {} }; req.results.geojson = { geocoding: {} };
// REQUIRED. A semver.org compliant version number. Describes the version of // REQUIRED. A semver.org compliant version number. Describes the version of

2
middleware/renamePlacenames.js

@ -32,7 +32,7 @@ function setup() {
function renamePlacenames(req, res, next) { function renamePlacenames(req, res, next) {
// do nothing if no result data set // do nothing if no result data set
if (!req.results.data) { if (!req.results || !req.results.data) {
return next(); return next();
} }

8
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 // respond
return res.status(200).json(req.results.geojson); return res.status(200).json(req.results.geojson);
} }

Loading…
Cancel
Save