Show toast error when geojson/topojson file cannot be downloaded (#17502)

This commit is contained in:
Thomas Neirynck 2018-04-05 08:46:07 -04:00 committed by GitHub
parent fd37e90777
commit 82ac7762a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,7 +5,7 @@ import d3 from 'd3';
import { KibanaMapLayer } from '../../tile_map/public/kibana_map_layer';
import { truncatedColorMaps } from 'ui/vislib/components/color/truncated_colormaps';
import * as topojson from 'topojson-client';
import { toastNotifications } from 'ui/notify';
const EMPTY_STYLE = {
weight: 1,
@ -61,6 +61,7 @@ export default class ChoroplethLayer extends KibanaMapLayer {
this._showAllShapes = showAllShapes;
this._geojsonUrl = geojsonUrl;
this._leafletLayer = L.geoJson(null, {
onEachFeature: (feature, layer) => {
layer.on('click', () => {
@ -119,6 +120,21 @@ export default class ChoroplethLayer extends KibanaMapLayer {
} catch (e) {
this._loaded = true;
this._error = true;
let errorMessage;
if (e.status === 404) {
errorMessage = `Server responding with '404' when attempting to fetch ${geojsonUrl}.
Make sure the file exists at that location.`;
} else {
errorMessage = `Cannot download ${geojsonUrl} file. Please ensure the
CORS configuration of the server permits requests from the Kibana application on this host.`;
}
toastNotifications.addDanger({
title: 'Error downloading vector data',
text: errorMessage,
});
resolve();
}
});