Skip to content

Commit eefc093

Browse files
committed
Fix #24072: Don't throw an exception when there are no suitable edges near start/end points
Signed-off-by: Taylor Smock <[email protected]>
1 parent ac8db4c commit eefc093

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/main/java/org/openstreetmap/josm/plugins/routing2/lib/valhalla/ValhallaServer.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,17 @@ public Trip generateRoute(OsmDataLayer layer, JsonObject tripConfig, ILatLon...
238238
}
239239
// check if error
240240
if (data.containsKey("status_code") && 200 != data.getInt("status_code")) {
241-
if (data.getInt("error_code") == 442) {
242-
GuiHelper.runInEDTAndWait(
243-
() -> new Notification(tr("No route found")).setIcon(JOptionPane.WARNING_MESSAGE).show());
244-
return null; // No route found // FIXME: Throw RouteException with message?
245-
} // FIXME: Look through https://valhalla.github.io/valhalla/api/turn-by-turn/api-reference/#http-status-codes-and-conditions for other "valid" problems.
246-
throw new JosmRuntimeException(data.toString());
241+
final int errorCode = data.getInt("error_code");
242+
final String error = data.getString("error", "");
243+
// FIXME: Look through https://valhalla.github.io/valhalla/api/turn-by-turn/api-reference/#http-status-codes-and-conditions for other "valid" problems.
244+
switch (errorCode) {
245+
// 171: No suitable edges near location
246+
// 442: No path could be found for input
247+
case 171, 442 -> GuiHelper.runInEDTAndWait(() -> new Notification(tr("No route found\n{0}", error))
248+
.setIcon(JOptionPane.WARNING_MESSAGE).show());
249+
default -> throw new JosmRuntimeException(data.toString());
250+
}
251+
return null; // No route found // FIXME: Throw RouteException with message?
247252
}
248253
final JsonObject trip = data.getJsonObject("trip");
249254
final Locations[] locations1 = trip.getJsonArray("locations").stream().map(ValhallaServer::parseLocation)

0 commit comments

Comments
 (0)