Error handling

This commit is contained in:
2024-08-05 23:32:16 +03:00
parent 8a4e2dc467
commit 9f76228ebe
21 changed files with 209 additions and 117 deletions

View File

@ -5,13 +5,13 @@ pub struct Params {
user_id: i32,
}
type Response = Result<Json<db::users::UserInfo>, StatusCode>;
type Response = GeneralResult<Json<db::users::UserInfo>>;
pub async fn get(State(pool): State<Pool>, Query(params): Query<Params>) -> Response {
let info = db::users::get(params.user_id, &pool)
.await
.handle_internal()?
.ok_or(StatusCode::NOT_FOUND)?;
.handle_internal("Error getting the user")?
.handle(StatusCode::NOT_FOUND, "User not found")?;
Ok(Json(info))
}