From 12c791ce60c33eab5277bb4e47c688285235d480 Mon Sep 17 00:00:00 2001 From: MV88 Date: Wed, 18 Oct 2023 12:23:48 +0200 Subject: [PATCH] Fix #9620 better error handling of GeoProcessing --- web/client/epics/geoProcessing.js | 116 ++++++++++++++++++++---- web/client/observables/wfs.js | 4 +- web/client/translations/data.de-DE.json | 5 +- web/client/translations/data.en-US.json | 5 +- web/client/translations/data.es-ES.json | 5 +- web/client/translations/data.fr-FR.json | 5 +- web/client/translations/data.it-IT.json | 5 +- web/client/utils/DebugUtils.js | 12 ++- 8 files changed, 130 insertions(+), 27 deletions(-) diff --git a/web/client/epics/geoProcessing.js b/web/client/epics/geoProcessing.js index e5812825b7..db0e69f5a2 100644 --- a/web/client/epics/geoProcessing.js +++ b/web/client/epics/geoProcessing.js @@ -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'; @@ -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) @@ -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)))); @@ -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", @@ -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", @@ -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", @@ -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); @@ -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); @@ -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, @@ -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( @@ -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", @@ -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", diff --git a/web/client/observables/wfs.js b/web/client/observables/wfs.js index 6a3e2250a0..f4ceb01995 100644 --- a/web/client/observables/wfs.js +++ b/web/client/observables/wfs.js @@ -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'; @@ -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) : []) ]), diff --git a/web/client/translations/data.de-DE.json b/web/client/translations/data.de-DE.json index 72d655d4c4..2155d76f0b 100644 --- a/web/client/translations/data.de-DE.json +++ b/web/client/translations/data.de-DE.json @@ -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?", diff --git a/web/client/translations/data.en-US.json b/web/client/translations/data.en-US.json index d7f1b70bc0..2a5f332d45 100644 --- a/web/client/translations/data.en-US.json +++ b/web/client/translations/data.en-US.json @@ -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?", diff --git a/web/client/translations/data.es-ES.json b/web/client/translations/data.es-ES.json index 344b80b0c5..5acf75b543 100644 --- a/web/client/translations/data.es-ES.json +++ b/web/client/translations/data.es-ES.json @@ -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?", diff --git a/web/client/translations/data.fr-FR.json b/web/client/translations/data.fr-FR.json index bf60b12b8c..b1a8c52037 100644 --- a/web/client/translations/data.fr-FR.json +++ b/web/client/translations/data.fr-FR.json @@ -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 ?", diff --git a/web/client/translations/data.it-IT.json b/web/client/translations/data.it-IT.json index 8e0412c991..3b288287e3 100644 --- a/web/client/translations/data.it-IT.json +++ b/web/client/translations/data.it-IT.json @@ -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?", diff --git a/web/client/utils/DebugUtils.js b/web/client/utils/DebugUtils.js index fb6731d1c2..a7419faf7b 100644 --- a/web/client/utils/DebugUtils.js +++ b/web/client/utils/DebugUtils.js @@ -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() }); }