diff --git a/rest/src/main/java/com/netflix/conductor/rest/controllers/TaskResource.java b/rest/src/main/java/com/netflix/conductor/rest/controllers/TaskResource.java index bad7968a9..d5d80ecf2 100644 --- a/rest/src/main/java/com/netflix/conductor/rest/controllers/TaskResource.java +++ b/rest/src/main/java/com/netflix/conductor/rest/controllers/TaskResource.java @@ -16,6 +16,7 @@ import java.util.Map; import java.util.Optional; +import com.netflix.conductor.core.exception.NotFoundException; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -71,8 +72,8 @@ public ResponseEntity> batchPoll( @RequestParam(value = "count", defaultValue = "1") int count, @RequestParam(value = "timeout", defaultValue = "100") int timeout) { // 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)) + return Optional.ofNullable(taskService.batchPoll(taskType, workerId, domain, count, timeout)) + .filter(tasks -> !tasks.isEmpty()) .map(ResponseEntity::ok) .orElse(ResponseEntity.noContent().build()); } @@ -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 getTaskLogs(@PathVariable("taskId") String taskId) { - return taskService.getTaskLogs(taskId); + public ResponseEntity> getTaskLogs(@PathVariable("taskId") String taskId) { + return Optional.ofNullable(taskService.getTaskLogs(taskId)) + .filter(logs -> !logs.isEmpty()) + .map(ResponseEntity::ok) + .orElseThrow(() -> new NotFoundException("Task logs not found for taskId: %s", taskId)); } @GetMapping("/{taskId}") @@ -113,7 +117,7 @@ public ResponseEntity 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()); + .orElseThrow(() -> new NotFoundException("Task not found for taskId: %s", taskId)); } @GetMapping("/queue/sizes")