From c4206f0ec1e0729605514bafb6724ea90e2c6598 Mon Sep 17 00:00:00 2001 From: qqmyers Date: Sun, 17 Aug 2025 11:18:54 -0400 Subject: [PATCH] properly handle not found --- .../edu/harvard/iq/dataverse/api/Admin.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/api/Admin.java b/src/main/java/edu/harvard/iq/dataverse/api/Admin.java index ac52b5d9fbf..d55f582ecae 100644 --- a/src/main/java/edu/harvard/iq/dataverse/api/Admin.java +++ b/src/main/java/edu/harvard/iq/dataverse/api/Admin.java @@ -1243,6 +1243,14 @@ public Response validateDataset(@PathParam("id") String id, @QueryParam("variabl @Produces({"application/json"}) public Response validateDatasetDatafiles(@PathParam("id") String id) { + Dataset dataset; + // First check if the dataset exists before starting the streaming output + try { + dataset = findDatasetOrDie(id); + } catch (WrappedResponse wr) { + return wr.getResponse(); // This will return the proper 404 Not Found response + } + // Streaming output: the API will start producing // the output right away, as it goes through the list // of the datafiles in the dataset. @@ -1252,23 +1260,13 @@ public Response validateDatasetDatafiles(@PathParam("id") String id) { @Override public void write(OutputStream os) throws IOException, WebApplicationException { - Dataset dataset; - - try { - dataset = findDatasetOrDie(id); - } catch (Exception ex) { - throw new IOException(ex.getMessage()); - } os.write("{\"dataFiles\": [\n".getBytes()); boolean wroteObject = false; for (DataFile dataFile : dataset.getFiles()) { - // Potentially, there's a godzillion datasets in this Dataverse. - // This is why we go through the list of ids here, and instantiate - // only one dataset at a time. + boolean success = false; - boolean constraintViolationDetected = false; JsonObjectBuilder output = Json.createObjectBuilder(); output.add("datafileId", dataFile.getId());