From 434dcf930c7d36292b9ea7a070ab48c768c17291 Mon Sep 17 00:00:00 2001 From: Trevor Gerhardt Date: Fri, 4 Oct 2024 21:47:06 +0800 Subject: [PATCH 1/2] Check if the config exists, return 404 if missing --- .../analysis/controllers/BundleController.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/conveyal/analysis/controllers/BundleController.java b/src/main/java/com/conveyal/analysis/controllers/BundleController.java index decd74a2c..a83160ad3 100644 --- a/src/main/java/com/conveyal/analysis/controllers/BundleController.java +++ b/src/main/java/com/conveyal/analysis/controllers/BundleController.java @@ -18,8 +18,8 @@ import com.conveyal.gtfs.validator.PostLoadValidator; import com.conveyal.osmlib.Node; import com.conveyal.osmlib.OSM; -import com.conveyal.r5.analyst.progress.ProgressInputStream; import com.conveyal.r5.analyst.cluster.TransportNetworkConfig; +import com.conveyal.r5.analyst.progress.ProgressInputStream; import com.conveyal.r5.analyst.progress.Task; import com.conveyal.r5.streets.OSMCache; import com.conveyal.r5.util.ExceptionUtils; @@ -327,13 +327,17 @@ private Bundle getBundle (Request req, Response res) { * and is considered the definitive source of truth. The entry in the database is a newer addition and has only * been around since September 2024. */ - private TransportNetworkConfig getBundleConfig (Request request, Response res) { + private TransportNetworkConfig getBundleConfig(Request request, Response res) throws IOException { // Unfortunately this mimics logic in TransportNetworkCache. Deduplicate in a static utility method? String id = GTFSCache.cleanId(request.params("_id")); FileStorageKey key = new FileStorageKey(BUNDLES, id, "json"); File networkConfigFile = fileStorage.getFile(key); + if (!networkConfigFile.exists()) { + throw AnalysisServerException.notFound("Bundle configuration file could not be found."); + } + // Unlike in the worker, we expect the backend to have a model field for every known network/bundle option. - // Threfore, use the default objectMapper that does not tolerate unknown fields. + // Therefore, use the default objectMapper that does not tolerate unknown fields. try { return JsonUtil.objectMapper.readValue(networkConfigFile, TransportNetworkConfig.class); } catch (Exception exception) { From cd7840c2c75b8123be51b569284bbaf03e0e2bfb Mon Sep 17 00:00:00 2001 From: Trevor Gerhardt Date: Fri, 4 Oct 2024 21:49:06 +0800 Subject: [PATCH 2/2] Remove unnecessary throws clause --- .../com/conveyal/analysis/controllers/BundleController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/conveyal/analysis/controllers/BundleController.java b/src/main/java/com/conveyal/analysis/controllers/BundleController.java index a83160ad3..b493cf618 100644 --- a/src/main/java/com/conveyal/analysis/controllers/BundleController.java +++ b/src/main/java/com/conveyal/analysis/controllers/BundleController.java @@ -327,7 +327,7 @@ private Bundle getBundle (Request req, Response res) { * and is considered the definitive source of truth. The entry in the database is a newer addition and has only * been around since September 2024. */ - private TransportNetworkConfig getBundleConfig(Request request, Response res) throws IOException { + private TransportNetworkConfig getBundleConfig(Request request, Response res) { // Unfortunately this mimics logic in TransportNetworkCache. Deduplicate in a static utility method? String id = GTFSCache.cleanId(request.params("_id")); FileStorageKey key = new FileStorageKey(BUNDLES, id, "json");