Skip to content

Commit

Permalink
fix: show an alert when a load error occurs (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
amcgee committed Apr 25, 2019
1 parent a2a16d6 commit edb3f30
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src/loaders/eventLoader.js
Expand Up @@ -21,10 +21,37 @@ import { cssColor } from '../util/colors';
// Server clustering if more than 2000 events
const useServerCluster = count => count > 2000; // TODO: Use constant

const accessDeniedAlert = createAlert(
i18n.t('Access denied'),
i18n.t('user is not allowed to read layer data')
);
const unknownErrorAlert = createAlert(
i18n.t('Failed'),
i18n.t('an unknown error occurred while reading layer data')
);

// TODO: Refactor to share code with other loaders
// Returns a promise
const eventLoader = async layerConfig => {
const config = { ...layerConfig };
let config = { ...layerConfig };
try {
await loadEventLayer(config);
} catch (e) {
if (e.httpStatusCode === 403 || e.httpStatusCode === 409) {
config.alerts = [accessDeniedAlert];
} else {
config.alerts = [unknownErrorAlert];
}
}

config.isLoaded = true;
config.isExpanded = true;
config.isVisible = true;

return config;
};

const loadEventLayer = async config => {
const {
columns,
endDate,
Expand Down Expand Up @@ -104,12 +131,6 @@ const eventLoader = async layerConfig => {
if (alert) {
config.alerts = [alert];
}

config.isLoaded = true;
config.isExpanded = true;
config.isVisible = true;

return config;
};

// Also used to query for server cluster in map/EventLayer.js
Expand Down

0 comments on commit edb3f30

Please sign in to comment.