diff --git a/README.md b/README.md
index 39b034ac..655ee8d8 100644
--- a/README.md
+++ b/README.md
@@ -599,6 +599,7 @@ If the aspect ratio of your custom map is not the default `16:9` (`0.5625`), you
width: null, // If not null, datamaps will grab the width of 'element',
responsive: false, // If true, call `resize()` on the map object when it should adjust it's size
done: function() {}, // Callback when the map is done drawing
+ error: null, // If not null, callback when the map cannot fetch the dataUrl
fills: {
defaultFill: '#ABDDA4' // The keys in this object map to the "fillKey" of [data] or [bubbles]
},
diff --git a/src/examples/custom-map-data-error-handling.html b/src/examples/custom-map-data-error-handling.html
new file mode 100644
index 00000000..3df85680
--- /dev/null
+++ b/src/examples/custom-map-data-error-handling.html
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+ Custom Map Data Error Handling
+
+
+
+
\ No newline at end of file
diff --git a/src/index.d.ts b/src/index.d.ts
index 1700fb09..9376060b 100644
--- a/src/index.d.ts
+++ b/src/index.d.ts
@@ -14,6 +14,7 @@ declare interface DataMapOptions {
path: d3.geo.Path;
projection: d3.geo.Projection;
}) => void;
+ error?: (error: any) => void;
responsive?: boolean;
projection?: string;
height?: null | number;
diff --git a/src/js/datamaps.js b/src/js/datamaps.js
index 121e2711..65bad681 100644
--- a/src/js/datamaps.js
+++ b/src/js/datamaps.js
@@ -13,6 +13,7 @@
dataType: 'json',
data: {},
done: function() {},
+ error: null,
fills: {
defaultFill: '#ABDDA4'
},
@@ -765,7 +766,14 @@
// If custom URL for topojson data, retrieve it and render
if ( options.geographyConfig.dataUrl ) {
d3.json( options.geographyConfig.dataUrl, function(error, results) {
- if ( error ) throw new Error(error);
+ if ( error ) {
+ if ( self.options.error ) {
+ self.options.error(error);
+ return;
+ }
+
+ throw new Error(error);
+ }
self.customTopo = results;
draw( results );
});