Skip to content

Commit

Permalink
Make sure that when fetching a Note by id that doesn't exist returns …
Browse files Browse the repository at this point in the history
…a 404 Not Found error. Also make sure an empty list of Notes is returned as an empty list and not a 404 Not Found
  • Loading branch information
jhodapp committed Aug 2, 2024
1 parent 65ec8dd commit e03376f
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 23 deletions.
22 changes: 1 addition & 21 deletions entity_api/src/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,7 @@ pub async fn find_by(
}
}

match query.all(db).await {
Ok(notes) => {
debug!("Note found: {:?}", notes);

if !notes.is_empty() {
Ok(notes)
} else {
Err(Error {
inner: None,
error_code: EntityApiErrorCode::RecordNotFound,
})
}
}
Err(err) => {
error!("Error encountered retrieving all notes {}", err);
Err(Error {
inner: None,
error_code: EntityApiErrorCode::SystemError,
})
}
}
Ok(query.all(db).await?)
}

#[cfg(test)]
Expand Down
1 change: 0 additions & 1 deletion web/src/controller/note_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ pub async fn index(
),
responses(
(status = 200, description = "Successfully retrieved a certain Note by its id", body = [entity::notes::Model]),
(status = 204, description = "No content"),
(status = 401, description = "Unauthorized"),
(status = 404, description = "Note not found"),
(status = 405, description = "Method not allowed")
Expand Down
2 changes: 1 addition & 1 deletion web/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl IntoResponse for Error {
EntityApiErrorCode::RecordNotFound => {
debug!("Error: {:#?}, mapping to NO_CONTENT", self);

(StatusCode::NO_CONTENT, "NO CONTENT").into_response()
(StatusCode::NOT_FOUND, "NOT FOUND").into_response()
}
EntityApiErrorCode::RecordNotUpdated => {
debug!("Error: {:#?}, mapping to UNPROCESSABLE_ENTITY", self);
Expand Down

0 comments on commit e03376f

Please sign in to comment.