Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try/catch extent() #124

Merged
merged 3 commits into from
May 6, 2015
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion helper/geojsonify.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ function search( docs, params ){
var geojson = GeoJSON.parse( geodata, { Point: ['lat', 'lng'] });

// add bbox
geojson.bbox = extent( geojson ) || undefined;
try {
geojson.bbox = extent( geojson ) || undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks a bit odd to have the || conditional inside a try/catch and after the thing that might throw. would be cleaner as

geojson.bbox = undefined;
try {
  geojson.bbox = extent( geojson )
}
catch (e) {
  // ...
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, I think this is because extent() can return null which ends up in the JSON payload, I totally agree it doesn't feel right, will give it a rejig.

} catch( e ){
console.error( 'bbox error', e.message, e.stack );
console.error( 'geojson', JSON.stringify( geojson, null, 2 ) );
}

return geojson;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"dependencies": {
"async": "^0.9.0",
"express": "^4.8.8",
"geojson": "^0.2.0",
"geojson": "^0.2.1",
"geojson-extent": "^0.3.1",
"geopipes-elasticsearch-backend": "0.0.12",
"is-object": "^1.0.1",
Expand Down
24 changes: 24 additions & 0 deletions test/unit/helper/geojsonify.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,30 @@ module.exports.tests.interface = function(test, common) {
});
};

// ref: https://github.com/pelias/pelias/issues/84
module.exports.tests.earth = function(test, common) {

var earth = [{
'_type': 'geoname',
'_id': '6295630',
'name': {
'default': 'Earth'
},
'center_point': {
'lon': 0,
'lat': 0
}
}];

test('earth', function(t) {
t.doesNotThrow(function(){
geojsonify.search( earth, { details: true } );
});
t.end();
});

};

module.exports.tests.search = function(test, common) {

var input = [
Expand Down