Manager: more graceful errors when receiving task update of unknown task

Return a 404 Not Found when the task can't be found, and a 500 on other
errors.
This commit is contained in:
Sybren A. Stüvel 2022-04-21 19:03:51 +02:00
parent 1176d85496
commit 6bdc198301

View File

@ -171,7 +171,10 @@ func (f *Flamenco) TaskUpdate(e echo.Context, taskID string) error {
dbTask, err := f.persist.FetchTask(ctx, taskID)
if err != nil {
logger.Warn().Err(err).Msg("cannot fetch task")
return sendAPIError(e, http.StatusNotFound, "task %+v not found", taskID)
if errors.Is(err, persistence.ErrTaskNotFound) {
return sendAPIError(e, http.StatusNotFound, "task %+v not found", taskID)
}
return sendAPIError(e, http.StatusInternalServerError, "error fetching task")
}
if dbTask == nil {
panic("task could not be fetched, but database gave no error either")