When task doesn't exist while it was requested the codebase fails with NPE which results in 500 response. Rework it to gracefully handle such cases and let client know that task is missing.
The example of code that fails
|
@Override |
|
public ResponseEntity<TaskWithoutData> getTask(@PathVariable final String taskId) { |
|
return callWithAuthentication(() -> { |
|
FullTaskRecord task = taskDao.getTask(UUID.fromString(taskId), FullTaskRecord.class); |
|
return ResponseEntity.ok(new TaskWithoutData() |
|
.setId(taskId) |
|
.setVersion(task.getVersion()) |
|
.setStatus(task.getStatus()) |
|
.setType(task.getType()) |
|
.setSubType(task.getSubType()) |
|
.setNextEventTime(Date.from(task.getNextEventTime().toInstant())) |
|
.setStateTime(Date.from(task.getStateTime().toInstant())) |
|
.setPriority(task.getPriority()) |
|
.setProcessingTriesCount(task.getProcessingTriesCount()) |
|
.setProcessingClientId(task.getProcessingClientId())); |
|
}); |
|
} |