Skip to content

Commit 2950260

Browse files
committed
Improve response sstatus code when query return no results
1 parent 08b7300 commit 2950260

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

docs/site/content/en/openapi/openapi.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,10 @@ paths:
666666
description: The run data will be processed asynchronously
667667
content:
668668
text/plain: {}
669+
"204":
670+
description: Data is valid but no run was created
671+
content:
672+
text/plain: {}
669673
"400":
670674
description: Some fields are missing or invalid
671675
content:

horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/services/RunService.java

+1
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ Response add(@QueryParam("test") String testNameOrId,
222222
@APIResponses(value = {
223223
@APIResponse(responseCode = "200", description = "id of the newly generated run", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(type = SchemaType.INTEGER, implementation = Integer.class), example = "101")),
224224
@APIResponse(responseCode = "202", description = "The run data will be processed asynchronously", content = @Content(mediaType = MediaType.TEXT_PLAIN)),
225+
@APIResponse(responseCode = "204", description = "Data is valid but no run was created", content = @Content(mediaType = MediaType.TEXT_PLAIN)),
225226
@APIResponse(responseCode = "400", description = "Some fields are missing or invalid", content = @Content(mediaType = MediaType.APPLICATION_JSON))
226227
})
227228
@Operation(description = "Upload a new Run")

horreum-backend/src/main/java/io/hyperfoil/tools/horreum/svc/RunServiceImpl.java

+4
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,10 @@ Response addRunFromData(String start, String stop, String test,
502502
if (datastore.uploadType() == Datastore.UploadType.MUILTI
503503
&& response.payload instanceof ArrayNode) {
504504

505+
if (response.payload.isEmpty()) {
506+
return Response.status(Response.Status.NO_CONTENT).entity("Query returned no results").build();
507+
}
508+
505509
//if we return more than 10 results, offload to async queue to process - this might take a LOOONG time
506510
if (response.payload.size() > 10) {
507511
response.payload.forEach(jsonNode -> {

0 commit comments

Comments
 (0)