From dd94a7d613f4363ac30a9a99087c56decca46e7a Mon Sep 17 00:00:00 2001 From: vcoppe Date: Sat, 7 Mar 2026 15:57:58 +0100 Subject: [PATCH] catch graphhopper exceptions --- .../toolbar/tools/routing/routing-controls.ts | 12 +------ .../toolbar/tools/routing/routing.ts | 31 +++++++++++++++++-- website/src/locales/en.json | 2 ++ 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/website/src/lib/components/toolbar/tools/routing/routing-controls.ts b/website/src/lib/components/toolbar/tools/routing/routing-controls.ts index 57fb3be89..6db0a4e38 100644 --- a/website/src/lib/components/toolbar/tools/routing/routing-controls.ts +++ b/website/src/lib/components/toolbar/tools/routing/routing-controls.ts @@ -731,17 +731,7 @@ export class RoutingControls { try { response = await route(targetCoordinates); } catch (e: any) { - if (e.message.includes('from-position not mapped in existing datafile')) { - toast.error(i18n._('toolbar.routing.error.from')); - } else if (e.message.includes('via1-position not mapped in existing datafile')) { - toast.error(i18n._('toolbar.routing.error.via')); - } else if (e.message.includes('to-position not mapped in existing datafile')) { - toast.error(i18n._('toolbar.routing.error.to')); - } else if (e.message.includes('Time-out')) { - toast.error(i18n._('toolbar.routing.error.timeout')); - } else { - toast.error(e.message); - } + toast.error(i18n._(e.message, e.message)); return false; } diff --git a/website/src/lib/components/toolbar/tools/routing/routing.ts b/website/src/lib/components/toolbar/tools/routing/routing.ts index cf7fe968f..924330283 100644 --- a/website/src/lib/components/toolbar/tools/routing/routing.ts +++ b/website/src/lib/components/toolbar/tools/routing/routing.ts @@ -127,7 +127,23 @@ async function getGraphHopperRoute( }); if (!response.ok) { - throw new Error(`${await response.text()}`); + const error = await response.json(); + console.log(error); + if (error.message.includes('Cannot find point 0')) { + throw new Error('toolbar.routing.error.from'); + } else if (error.message.includes('Cannot find point 1')) { + if (points.length == 3) { + throw new Error('toolbar.routing.error.via'); + } else { + throw new Error('toolbar.routing.error.to'); + } + } else if (error.hints[0].details.includes('PointDistanceExceededException')) { + throw new Error('toolbar.routing.error.distance'); + } else if (error.hints[0].details.includes('ConnectionNotFoundException')) { + throw new Error('toolbar.routing.error.connection'); + } else { + throw new Error(error.message); + } } let json = await response.json(); @@ -186,7 +202,18 @@ async function getBRouterRoute( let response = await fetch(url); if (!response.ok) { - throw new Error(`${await response.text()}`); + const error = await response.text(); + if (error.includes('from-position not mapped in existing datafile')) { + throw new Error('toolbar.routing.error.from'); + } else if (error.includes('via1-position not mapped in existing datafile')) { + throw new Error('toolbar.routing.error.via'); + } else if (error.includes('to-position not mapped in existing datafile')) { + throw new Error('toolbar.routing.error.to'); + } else if (error.includes('Time-out')) { + throw new Error('toolbar.routing.error.timeout'); + } else { + throw new Error(error); + } } let geojson = await response.json(); diff --git a/website/src/locales/en.json b/website/src/locales/en.json index 4bf445f04..b5fa2853d 100644 --- a/website/src/locales/en.json +++ b/website/src/locales/en.json @@ -190,6 +190,8 @@ "from": "The start point is too far from the nearest road", "via": "The via point is too far from the nearest road", "to": "The end point is too far from the nearest road", + "distance": "The end point is to far from the start point", + "connection": "No connection found between the points", "timeout": "Route calculation took too long, try adding points closer together" } },