transferwise/tw-tasks-executor

Gracefully handle absence of tasks in management extension

yevhenii0 opened this issue · 1 comments

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()));
});
}

Stale issue message