Skip to content

Commit

Permalink
Using NotFoundException when entity is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
Vamshi Gopari committed Feb 15, 2024
1 parent 828bc5a commit 8bf7e90
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,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.notFound().build());
.orElseThrow(() -> new NotFoundException("Poll not found for Task Type: %s", taskType));
}

@GetMapping("/poll/batch/{tasktype}")
Expand All @@ -76,7 +76,7 @@ public ResponseEntity<List<Task>> batchPoll(
taskService.batchPoll(taskType, workerId, domain, count, timeout))
.filter(tasks -> !tasks.isEmpty())
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
.orElseThrow(() -> new NotFoundException("Batch Poll not found for Task Type: %s", taskType));
}

@PostMapping(produces = TEXT_PLAIN_VALUE)
Expand Down Expand Up @@ -118,7 +118,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.notFound().build());
.orElseThrow(() -> new NotFoundException("Task not found for taskId: %s", taskId));
}

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

0 comments on commit 8bf7e90

Please sign in to comment.