avatar: return 404 if user does not exist
This commit is contained in:
parent
1fd7901037
commit
5b8fef624d
2 changed files with 7 additions and 1 deletions
|
|
@ -39,4 +39,8 @@ impl Error {
|
||||||
pub fn internal_server_error<E: std::error::Error>(error: E) -> Self {
|
pub fn internal_server_error<E: std::error::Error>(error: E) -> Self {
|
||||||
Self::new(Status::InternalServerError, error)
|
Self::new(Status::InternalServerError, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn not_found<M: std::fmt::Display>(value: M) -> Self {
|
||||||
|
Self::new(Status::NotFound, value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,9 @@ async fn avatar(
|
||||||
size: Option<u32>,
|
size: Option<u32>,
|
||||||
) -> Result<FileFromBytes> {
|
) -> Result<FileFromBytes> {
|
||||||
// Verify existence of user
|
// 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
|
// Generate avatar
|
||||||
let avatar = task::spawn_blocking(move || {
|
let avatar = task::spawn_blocking(move || {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue