Skip to content

Commit

Permalink
Extra error checks
Browse files Browse the repository at this point in the history
  • Loading branch information
veltman committed Nov 17, 2014
1 parent d562fd8 commit 3d57068
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions wherewolf.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

//If it has a 'type' property
//Check for a FeatureCollection or Topology
if (collection.type) {
if (collection && collection.type) {

//Check for a FeatureCollection
if (collection.type === "FeatureCollection") {
Expand All @@ -49,6 +49,11 @@

features = _convertTopo(collection,key);


} else if (collection.type === "Feature") {

features = [collection];

}

//If it's an array
Expand All @@ -57,8 +62,10 @@

features = collection;

}

//Not valid
} else {
if (!features) {

throw new TypeError("No valid GeoJSON or TopoJSON supplied.");

Expand Down Expand Up @@ -245,7 +252,8 @@
//Convert a Topology object to a FeatureCollection
function _convertTopo(collection,key) {

var features;
var converted,
features;

//Check that topojson exists
if (!tj) {
Expand Down Expand Up @@ -293,8 +301,14 @@

}

//Get the FeatureCollection from the object named 'key'
var converted = tj.feature(collection,collection.objects[key]);
try {
//Get the FeatureCollection from the object named 'key'
converted = tj.feature(collection,collection.objects[key]);
} catch(e) {

throw new TypeError("Invalid TopoJSON.");

}

//If it returns a single Feature, turn that into an array
if (converted.type === "Feature") {
Expand Down

0 comments on commit 3d57068

Please sign in to comment.