Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue: Return 404 instead of 2xx codes for methods handling non-existent tasks#38 #69

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public ResponseEntity<Task> poll(
// for backwards compatibility with 2.x client which expects a 204 when no Task is found
return Optional.ofNullable(taskService.poll(taskType, workerId, domain))
.map(ResponseEntity::ok)
.orElse(ResponseEntity.noContent().build());
.orElse(ResponseEntity.notFound().build());
}

@GetMapping("/poll/batch/{tasktype}")
Expand All @@ -73,8 +73,9 @@ public ResponseEntity<List<Task>> batchPoll(
// for backwards compatibility with 2.x client which expects a 204 when no Task is found
return Optional.ofNullable(
taskService.batchPoll(taskType, workerId, domain, count, timeout))
.filter(tasks -> !tasks.isEmpty())
.map(ResponseEntity::ok)
.orElse(ResponseEntity.noContent().build());
.orElse(ResponseEntity.notFound().build());
}

@PostMapping(produces = TEXT_PLAIN_VALUE)
Expand Down Expand Up @@ -103,8 +104,11 @@ public void log(@PathVariable("taskId") String taskId, @RequestBody String log)

@GetMapping("/{taskId}/log")
@Operation(summary = "Get Task Execution Logs")
public List<TaskExecLog> getTaskLogs(@PathVariable("taskId") String taskId) {
return taskService.getTaskLogs(taskId);
public ResponseEntity<List<TaskExecLog>> getTaskLogs(@PathVariable("taskId") String taskId) {
vgopari marked this conversation as resolved.
Show resolved Hide resolved
return Optional.ofNullable(taskService.getTaskLogs(taskId))
.filter(logs -> !logs.isEmpty())
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}

@GetMapping("/{taskId}")
Expand All @@ -113,7 +117,7 @@ public ResponseEntity<Task> getTask(@PathVariable("taskId") String taskId) {
// for backwards compatibility with 2.x client which expects a 204 when no Task is found
return Optional.ofNullable(taskService.getTask(taskId))
.map(ResponseEntity::ok)
.orElse(ResponseEntity.noContent().build());
.orElse(ResponseEntity.notFound().build());
}

@GetMapping("/queue/sizes")
Expand Down