Skip to content

Commit dc1f57c

Browse files
authored
Merge pull request #69 from vmsh1/vgopari-fix-incorrect-status-codes-#38
Fix issue: Return 404 instead of 2xx codes for methods handling non-existent tasks#38
2 parents 919c416 + b47d627 commit dc1f57c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

rest/src/main/java/com/netflix/conductor/rest/controllers/TaskResource.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.Map;
1717
import java.util.Optional;
1818

19+
import com.netflix.conductor.core.exception.NotFoundException;
1920
import org.springframework.http.ResponseEntity;
2021
import org.springframework.web.bind.annotation.GetMapping;
2122
import org.springframework.web.bind.annotation.PathVariable;
@@ -79,8 +80,8 @@ public ResponseEntity<List<Task>> batchPoll(
7980
@RequestParam(value = "count", defaultValue = "1") int count,
8081
@RequestParam(value = "timeout", defaultValue = "100") int timeout) {
8182
// for backwards compatibility with 2.x client which expects a 204 when no Task is found
82-
return Optional.ofNullable(
83-
taskService.batchPoll(taskType, workerId, domain, count, timeout))
83+
return Optional.ofNullable(taskService.batchPoll(taskType, workerId, domain, count, timeout))
84+
.filter(tasks -> !tasks.isEmpty())
8485
.map(ResponseEntity::ok)
8586
.orElse(ResponseEntity.noContent().build());
8687
}
@@ -151,8 +152,11 @@ public void log(@PathVariable("taskId") String taskId, @RequestBody String log)
151152

152153
@GetMapping("/{taskId}/log")
153154
@Operation(summary = "Get Task Execution Logs")
154-
public List<TaskExecLog> getTaskLogs(@PathVariable("taskId") String taskId) {
155-
return taskService.getTaskLogs(taskId);
155+
public ResponseEntity<List<TaskExecLog>> getTaskLogs(@PathVariable("taskId") String taskId) {
156+
return Optional.ofNullable(taskService.getTaskLogs(taskId))
157+
.filter(logs -> !logs.isEmpty())
158+
.map(ResponseEntity::ok)
159+
.orElseThrow(() -> new NotFoundException("Task logs not found for taskId: %s", taskId));
156160
}
157161

158162
@GetMapping("/{taskId}")
@@ -161,7 +165,7 @@ public ResponseEntity<Task> getTask(@PathVariable("taskId") String taskId) {
161165
// for backwards compatibility with 2.x client which expects a 204 when no Task is found
162166
return Optional.ofNullable(taskService.getTask(taskId))
163167
.map(ResponseEntity::ok)
164-
.orElse(ResponseEntity.noContent().build());
168+
.orElseThrow(() -> new NotFoundException("Task not found for taskId: %s", taskId));
165169
}
166170

167171
@GetMapping("/queue/sizes")

0 commit comments

Comments
 (0)