diff --git a/crates/ezidam/src/error.rs b/crates/ezidam/src/error.rs index 05e109a..70e0eb4 100644 --- a/crates/ezidam/src/error.rs +++ b/crates/ezidam/src/error.rs @@ -39,4 +39,8 @@ impl Error { pub fn internal_server_error(error: E) -> Self { Self::new(Status::InternalServerError, error) } + + pub fn not_found(value: M) -> Self { + Self::new(Status::NotFound, value) + } } diff --git a/crates/ezidam/src/routes/root.rs b/crates/ezidam/src/routes/root.rs index a7a41c3..70a9f96 100644 --- a/crates/ezidam/src/routes/root.rs +++ b/crates/ezidam/src/routes/root.rs @@ -47,7 +47,9 @@ async fn avatar( size: Option, ) -> Result { // Verify existence of user - let _user = User::get_by_id(&mut *db, &user_id.0).await?; + let _user = User::get_by_id(&mut *db, &user_id.0) + .await? + .ok_or_else(|| Error::not_found(user_id.0.to_string()))?; // Generate avatar let avatar = task::spawn_blocking(move || {