Skip to content

Commit 5e55658

Browse files
authored
Merge pull request #11749 from GlobalDataverseCommunityConsortium/DD-1988-500_error_validating_files
DD-1988 - Fix /api/admin/validate/dataset/files/{id} error response
2 parents ab2c661 + c4206f0 commit 5e55658

File tree

1 file changed

+9
-11
lines changed
  • src/main/java/edu/harvard/iq/dataverse/api

1 file changed

+9
-11
lines changed

src/main/java/edu/harvard/iq/dataverse/api/Admin.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,14 @@ public Response validateDataset(@PathParam("id") String id, @QueryParam("variabl
12431243
@Produces({"application/json"})
12441244
public Response validateDatasetDatafiles(@PathParam("id") String id) {
12451245

1246+
Dataset dataset;
1247+
// First check if the dataset exists before starting the streaming output
1248+
try {
1249+
dataset = findDatasetOrDie(id);
1250+
} catch (WrappedResponse wr) {
1251+
return wr.getResponse(); // This will return the proper 404 Not Found response
1252+
}
1253+
12461254
// Streaming output: the API will start producing
12471255
// the output right away, as it goes through the list
12481256
// of the datafiles in the dataset.
@@ -1252,23 +1260,13 @@ public Response validateDatasetDatafiles(@PathParam("id") String id) {
12521260
@Override
12531261
public void write(OutputStream os) throws IOException,
12541262
WebApplicationException {
1255-
Dataset dataset;
1256-
1257-
try {
1258-
dataset = findDatasetOrDie(id);
1259-
} catch (Exception ex) {
1260-
throw new IOException(ex.getMessage());
1261-
}
12621263

12631264
os.write("{\"dataFiles\": [\n".getBytes());
12641265

12651266
boolean wroteObject = false;
12661267
for (DataFile dataFile : dataset.getFiles()) {
1267-
// Potentially, there's a godzillion datasets in this Dataverse.
1268-
// This is why we go through the list of ids here, and instantiate
1269-
// only one dataset at a time.
1268+
12701269
boolean success = false;
1271-
boolean constraintViolationDetected = false;
12721270

12731271
JsonObjectBuilder output = Json.createObjectBuilder();
12741272
output.add("datafileId", dataFile.getId());

0 commit comments

Comments
 (0)