16
16
import java .util .Map ;
17
17
import java .util .Optional ;
18
18
19
+ import com .netflix .conductor .core .exception .NotFoundException ;
19
20
import org .springframework .http .ResponseEntity ;
20
21
import org .springframework .web .bind .annotation .GetMapping ;
21
22
import org .springframework .web .bind .annotation .PathVariable ;
@@ -79,8 +80,8 @@ public ResponseEntity<List<Task>> batchPoll(
79
80
@ RequestParam (value = "count" , defaultValue = "1" ) int count ,
80
81
@ RequestParam (value = "timeout" , defaultValue = "100" ) int timeout ) {
81
82
// 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 ( ))
84
85
.map (ResponseEntity ::ok )
85
86
.orElse (ResponseEntity .noContent ().build ());
86
87
}
@@ -151,8 +152,11 @@ public void log(@PathVariable("taskId") String taskId, @RequestBody String log)
151
152
152
153
@ GetMapping ("/{taskId}/log" )
153
154
@ 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 ));
156
160
}
157
161
158
162
@ GetMapping ("/{taskId}" )
@@ -161,7 +165,7 @@ public ResponseEntity<Task> getTask(@PathVariable("taskId") String taskId) {
161
165
// for backwards compatibility with 2.x client which expects a 204 when no Task is found
162
166
return Optional .ofNullable (taskService .getTask (taskId ))
163
167
.map (ResponseEntity ::ok )
164
- .orElse ( ResponseEntity . noContent (). build ( ));
168
+ .orElseThrow (() -> new NotFoundException ( "Task not found for taskId: %s" , taskId ));
165
169
}
166
170
167
171
@ GetMapping ("/queue/sizes" )
0 commit comments