Skip to content

Commit

Permalink
Fix #9620 better error handling of GeoProcessing
Browse files Browse the repository at this point in the history
  • Loading branch information
MV88 committed Oct 18, 2023
1 parent 3d96f19 commit 12c791c
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 27 deletions.
116 changes: 97 additions & 19 deletions web/client/epics/geoProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ import {
calculateDistance
} from "../utils/CoordinatesUtils";
import {buildIdentifyRequest} from "../utils/MapInfoUtils";
import {logError} from "../utils/DebugUtils";
import {getFeatureInfo} from "../api/identify";
import {getFeatureSimple} from '../api/WFS';
import {findNonGeometryProperty} from '../utils/ogc/WFS/base';
Expand Down Expand Up @@ -211,7 +212,7 @@ export const checkWPSAvailabilityGPTEpic = (action$, store) => action$
);
})
.catch((e) => {
console.error(e);
logError(e);
return Rx.Observable.of(
setWPSAvailability(layerId, false, source),
checkingWPS(false)
Expand Down Expand Up @@ -270,8 +271,18 @@ export const getFeaturesGPTEpic = (action$, store) => action$
}
}, filterObj, options)
.map(data => setFeatures(layerId, source, data, page))
.catch(error => {
return Rx.Observable.of(setFeatures(layerId, source, error, page));
.catch(e => {
logError(e);
return Rx.Observable.of(
setFeatures(layerId, source, e, page),
showErrorNotification({
title: "errorTitleDefault",
message: "GeoProcessing.notifications.errorGettingFeaturesList",
autoDismiss: 6,
position: "tc",
values: {layerName: layer.name + " - " + layer.title}
})
);
})
.startWith(setFeatureLoading(true))
.concat(Rx.Observable.of(setFeatureLoading(false))));
Expand Down Expand Up @@ -316,7 +327,8 @@ export const getFeatureDataGPTEpic = (action$, store) => action$
]);

})
.catch(() => {
.catch((e) => {
logError(e);
return Rx.Observable.of(showErrorNotification({
title: "errorTitleDefault",
message: "GeoProcessing.notifications.errorGetFeature",
Expand Down Expand Up @@ -364,7 +376,8 @@ export const getIntersectionFeatureDataGPTEpic = (action$, store) => action$
]);

})
.catch(() => {
.catch((e) => {
logError(e);
return Rx.Observable.of(showErrorNotification({
title: "errorTitleDefault",
message: "GeoProcessing.notifications.errorGetFeature",
Expand Down Expand Up @@ -486,7 +499,8 @@ export const runBufferProcessGPTEpic = (action$, store) => action$
)
);
})
.catch(() => {
.catch((e) => {
logError(e);
return Rx.Observable.of(showErrorNotification({
title: "errorTitleDefault",
message: "GeoProcessing.notifications.errorBuffer",
Expand All @@ -504,19 +518,34 @@ export const runBufferProcessGPTEpic = (action$, store) => action$
executeOptions,
{
headers: {'Content-Type': 'application/xml', 'Accept': `application/xml, application/json`}
}).catch(() => {
return Rx.Observable.of(showErrorNotification({
title: "errorTitleDefault",
message: "GeoProcessing.notifications.errorBuffer",
autoDismiss: 6,
position: "tc"
}));
});
})
.catch((e) => {
logError(e);
return Rx.Observable.of({error: e, layerName: layer.name, layerTitle: layer.title});
});
return executeCollectProcess$
.switchMap((geom) => {
.switchMap((result) => {
if (result.error) {
if (result.error.message.includes("Failed to retrieve value for input features")) {
console.error("layerName " + result.layerName + " - " + result.layerTitle);
return Rx.Observable.of(showErrorNotification({
title: "errorTitleDefault",
message: "GeoProcessing.notifications.errorGettingFC",
autoDismiss: 6,
position: "tc",
values: {layerName: result.layerName + " - " + result.layerTitle}
}));
}
return Rx.Observable.of(showErrorNotification({
title: "errorTitleDefault",
message: "GeoProcessing.notifications.errorBuffer",
autoDismiss: 6,
position: "tc"
}));
}
const ft = {
type: "Feature",
geometry: geom
geometry: result
};
const featureReprojected = reprojectGeoJson(ft, "EPSG:4326", "EPSG:3857");
const geometry3857 = toWKT(featureReprojected.geometry);
Expand Down Expand Up @@ -574,6 +603,10 @@ export const runIntersectProcessGPTEpic = (action$, store) => action$
executeOptions,
{
headers: {'Content-Type': 'application/xml', 'Accept': `application/xml, application/json`}
})
.catch((e) => {
logError(e);
return Rx.Observable.of({error: e, layerName: layer.name, layerTitle: layer.title});
});
} else {
sourceFC$ = Rx.Observable.of(sourceFeature.geometry);
Expand All @@ -588,12 +621,46 @@ export const runIntersectProcessGPTEpic = (action$, store) => action$
executeOptions,
{
headers: {'Content-Type': 'application/xml', 'Accept': `application/xml, application/json`}
})
.catch((e) => {
logError(e);
return Rx.Observable.of({error: e, layerName: intersectionLayer.name, layerTitle: intersectionLayer.title});
});
} else {
intersectionFC$ = Rx.Observable.of(intersectionFeature.geometry);
}
return Rx.Observable.forkJoin(sourceFC$, intersectionFC$)
.switchMap(([firstGeom, secondGeom]) => {
if (firstGeom.error) {
const errorActions = [];
if (firstGeom.error.message.includes("Failed to retrieve value for input features")) {
logError(firstGeom.error);
errorActions.push(showErrorNotification({
title: "errorTitleDefault",
message: "GeoProcessing.notifications.errorGettingFC",
autoDismiss: 6,
position: "tc",
values: {layerName: firstGeom.layerName + " - " + firstGeom.layerTitle}
}));
}
if (secondGeom.error.message.includes("Failed to retrieve value for input features")) {
logError(secondGeom.error);
errorActions.push(showErrorNotification({
title: "errorTitleDefault",
message: "GeoProcessing.notifications.errorGettingFC",
autoDismiss: 6,
position: "tc",
values: {layerName: secondGeom.layerName + " - " + secondGeom.layerTitle}
}));
}
errorActions.push(showErrorNotification({
title: "errorTitleDefault",
message: "GeoProcessing.notifications.errorBuffer",
autoDismiss: 6,
position: "tc"
}));
return Rx.Observable.from(errorActions);
}

const executeProcess$ = executeProcess(
layerUrl,
Expand All @@ -616,7 +683,16 @@ export const runIntersectProcessGPTEpic = (action$, store) => action$
.switchMap((featureCollection) => {
const groups = groupsSelector(state);
const groupExist = find(groups, (g) => g.id === GPT_INTERSECTION_GROUP_ID);
const extent = getGeoJSONExtent(featureCollection);
let extent = getGeoJSONExtent(featureCollection);
if (extent.some(coord => coord === Infinity )) {
// intersection is empty, return a message
return Rx.Observable.of(showErrorNotification({
title: "errorTitleDefault",
message: "GeoProcessing.notifications.emptyIntersection",
autoDismiss: 6,
position: "tc"
}));
}
return (!groupExist ? Rx.Observable.of( addGroup("Intersected Layers", null, {id: GPT_INTERSECTION_GROUP_ID}, true)) : Rx.Observable.empty())
.concat(
Rx.Observable.of(
Expand Down Expand Up @@ -665,7 +741,8 @@ export const runIntersectProcessGPTEpic = (action$, store) => action$
})
));
})
.catch(() => {
.catch((e) => {
logError(e);
return Rx.Observable.of(showErrorNotification({
title: "errorTitleDefault",
message: "GeoProcessing.notifications.errorIntersectGFI",
Expand Down Expand Up @@ -804,7 +881,8 @@ export const clickToSelectFeatureGPTEpic = (action$, {getState}) =>
position: "tc"
}));
})
.catch(() => {
.catch((e) => {
logError(e);
return Rx.Observable.of(showErrorNotification({
title: "errorTitleDefault",
message: "GeoProcessing.notifications.errorGFI",
Expand Down
4 changes: 2 additions & 2 deletions web/client/observables/wfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import urlUtil from 'url';

import { castArray, isNil, isObject } from 'lodash';
import { isArray, castArray, isNil, isObject } from 'lodash';
import Rx from 'rxjs';
import { parseString } from 'xml2js';
import { stripPrefix } from 'xml2js/lib/processors';
Expand Down Expand Up @@ -259,7 +259,7 @@ export const getLayerJSONFeature = ({ search = {}, url, name } = {}, filter, {so
} : getFeature(
query(name,
[
sortBy(pn[0]),
sortBy(isArray(pn) ? pn[0] : pn),
...(pn ? [propertyName(pn)] : []),
...(filter ? castArray(filter) : [])
]),
Expand Down
5 changes: 4 additions & 1 deletion web/client/translations/data.de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -3977,7 +3977,10 @@
"noLayerSelected": "Bitte wählen Sie zuerst die Ebene aus.",
"successfulIntersection": "Der Schnittvorgang war erfolgreich und ein neuer Layer wurde erstellt und dem Inhaltsverzeichnis hinzugefügt",
"successfulBuffer": "Der Puffervorgang war erfolgreich und eine neue Ebene wurde erstellt und dem Inhaltsverzeichnis hinzugefügt",
"errorBuffer": "Der Puffervorgang ist fehlgeschlagen"
"errorBuffer": "Der Puffervorgang ist fehlgeschlagen",
"emptyIntersection": "Es gibt keine Schnittmenge zwischen den angegebenen Datensätzen.",
"errorGettingFC": "Es war nicht möglich, die Geometrie aus der Ebene zu erfassen {layerName}",
"errorGettingFeaturesList": "Es war nicht möglich, die Liste der Features aus dem Layer abzurufen {layerName}"
},
"warningTitle": "Warnung",
"warningBody": "Sie haben keine Funktion ausgewählt und dies kann die Leistung im Geoserver verlangsamen. Möchten Sie fortfahren?",
Expand Down
5 changes: 4 additions & 1 deletion web/client/translations/data.en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -3951,7 +3951,10 @@
"noLayerSelected": "Please select layer first.",
"successfulIntersection": "The intersection operation was successful and a new layer has ben created and added to the TOC",
"successfulBuffer": "The Buffer operation was successful and a new layer has ben created and added to the TOC",
"errorBuffer": "The Buffer operation has failed"
"errorBuffer": "The Buffer operation has failed",
"emptyIntersection": "There is no intersection between the given datasets.",
"errorGettingFC": "It was not possible to collect the geometry from the layer {layerName}",
"errorGettingFeaturesList": "It was not possible to fetch the list of features from the layer {layerName}"
},
"warningTitle": "Warning",
"warningBody": "You have not selected a feature and this may slow down performances in geoserver. Do you want to continue?",
Expand Down
5 changes: 4 additions & 1 deletion web/client/translations/data.es-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -3940,7 +3940,10 @@
"noLayerSelected": "Por favor seleccione la capa primero.",
"successfulIntersection": "La operación de intersección fue exitosa y se creó una nueva capa y se agregó a la tabla de contenido",
"successfulBuffer": "La operación de búfer fue exitosa y se creó una nueva capa y se agregó a la tabla de contenido",
"errorBuffer": "La operación de búfer ha fallado"
"errorBuffer": "La operación de búfer ha fallado",
"emptyIntersection": "No hay intersección entre los conjuntos de datos dados.",
"errorGettingFC": "No fue posible recopilar la geometría de la capa {layerName}",
"errorGettingFeaturesList": "No fue posible recuperar la lista de entidades de la capa {layerName}"
},
"warningTitle": "Advertencia",
"warningBody": "No ha seleccionado una función y esto puede ralentizar el rendimiento en el geoservidor. ¿Desea continuar?",
Expand Down
5 changes: 4 additions & 1 deletion web/client/translations/data.fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -3940,7 +3940,10 @@
"noLayerSelected": "Veuillez d'abord sélectionner le calque.",
"successfulIntersection": "L'opération d'intersection a réussi et une nouvelle couche a été créée et ajoutée à la table des matières",
"successfulBuffer": "L'opération Buffer a réussi et une nouvelle couche a été créée et ajoutée à la table des matières",
"errorBuffer": "L'opération Buffer a échoué"
"errorBuffer": "L'opération Buffer a échoué",
"emptyIntersection": "Il n'y a pas d'intersection entre les ensembles de données donnés.",
"errorGettingFC": "Il n'a pas été possible de collecter la géométrie du calque {layerName}",
"errorGettingFeaturesList": "Il n'a pas été possible de récupérer la liste des entités de la couche {layerName}"
},
"warningTitle": "Avertissement",
"warningBody": "Vous n'avez pas sélectionné de fonctionnalité et cela peut ralentir les performances de geoserver. Voulez-vous continuer ?",
Expand Down
5 changes: 4 additions & 1 deletion web/client/translations/data.it-IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -3940,7 +3940,10 @@
"noLayerSelected": "Seleziona prima il livello.",
"successfulIntersection": "L'operazione di intersezione è andata a buon fine e un nuovo livello è stato creato e aggiunto alla tabella dei contenuti",
"successfulBuffer": "L'operazione Buffer è andata a buon fine e un nuovo livello è stato creato e aggiunto alla tabella dei contenuti",
"errorBuffer": "L'operazione Buffer è fallita"
"errorBuffer": "L'operazione Buffer è fallita",
"emptyIntersection": "Non c'è una interesezione tra i dati utilizzati.",
"errorGettingFC": "Non è stato possibile ottenere la collezione di geometrie dal layer {layerName}",
"errorGettingFeaturesList": "Non è stato possibile ottenere la lista di features dal layer {layerName}"
},
"warningTitle": "Attenzione",
"warningBody": "Non hai selezionato una funzione e questo potrebbe rallentare le prestazioni del geoserver. Vuoi continuare?",
Expand Down
12 changes: 11 additions & 1 deletion web/client/utils/DebugUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,23 @@ import url from 'url';

const urlQuery = url.parse(window.location.href, true).query;

export const isDebugMode = () => {
return urlQuery && urlQuery.debug && __DEVTOOLS__;
};

export const logError = (error) => {
if (isDebugMode) {
console.error(error.message);
}
};

export function createDebugStore(reducer, initialState, userMiddlewares, enhancer) {
return createStore({
rootReducer: reducer,
state: initialState,
middlewares: userMiddlewares,
enhancer,
debug: urlQuery && urlQuery.debug && __DEVTOOLS__
debug: isDebugMode()
});
}

Expand Down

0 comments on commit 12c791c

Please sign in to comment.