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 @@ -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;
Expand Down Expand Up @@ -71,8 +72,8 @@ public ResponseEntity<List<Task>> 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());
}
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)
.orElseThrow(() -> new NotFoundException("Task logs not found for taskId: %s", taskId));
}

@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());
.orElseThrow(() -> new NotFoundException("Task not found for taskId: %s", taskId));
}

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