From eefc09374e1953a91b4a66401982a853ea4d5ff8 Mon Sep 17 00:00:00 2001 From: Taylor Smock Date: Thu, 9 Jan 2025 05:25:16 -0700 Subject: [PATCH] Fix #24072: Don't throw an exception when there are no suitable edges near start/end points Signed-off-by: Taylor Smock --- .../routing2/lib/valhalla/ValhallaServer.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/openstreetmap/josm/plugins/routing2/lib/valhalla/ValhallaServer.java b/src/main/java/org/openstreetmap/josm/plugins/routing2/lib/valhalla/ValhallaServer.java index 3de1992..d8ff58b 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/routing2/lib/valhalla/ValhallaServer.java +++ b/src/main/java/org/openstreetmap/josm/plugins/routing2/lib/valhalla/ValhallaServer.java @@ -238,12 +238,17 @@ public Trip generateRoute(OsmDataLayer layer, JsonObject tripConfig, ILatLon... } // check if error if (data.containsKey("status_code") && 200 != data.getInt("status_code")) { - if (data.getInt("error_code") == 442) { - GuiHelper.runInEDTAndWait( - () -> new Notification(tr("No route found")).setIcon(JOptionPane.WARNING_MESSAGE).show()); - return null; // No route found // FIXME: Throw RouteException with message? - } // FIXME: Look through https://valhalla.github.io/valhalla/api/turn-by-turn/api-reference/#http-status-codes-and-conditions for other "valid" problems. - throw new JosmRuntimeException(data.toString()); + final int errorCode = data.getInt("error_code"); + final String error = data.getString("error", ""); + // FIXME: Look through https://valhalla.github.io/valhalla/api/turn-by-turn/api-reference/#http-status-codes-and-conditions for other "valid" problems. + switch (errorCode) { + // 171: No suitable edges near location + // 442: No path could be found for input + case 171, 442 -> GuiHelper.runInEDTAndWait(() -> new Notification(tr("No route found\n{0}", error)) + .setIcon(JOptionPane.WARNING_MESSAGE).show()); + default -> throw new JosmRuntimeException(data.toString()); + } + return null; // No route found // FIXME: Throw RouteException with message? } final JsonObject trip = data.getJsonObject("trip"); final Locations[] locations1 = trip.getJsonArray("locations").stream().map(ValhallaServer::parseLocation)