Prevent crash from occuring

This commit is contained in:
Pierre HUBERT 2022-04-19 16:01:16 +02:00
parent 8cdb47a139
commit deb00c572d

View File

@ -6,6 +6,7 @@ use actix::Addr;
use actix_identity::Identity;
use actix_web::{Error, FromRequest, HttpRequest, web};
use actix_web::dev::Payload;
use actix_web::error::ErrorInternalServerError;
use crate::actors::users_actor;
use crate::actors::users_actor::UsersActor;
@ -41,9 +42,14 @@ impl FromRequest for CurrentUser {
Box::pin(async move {
let user: User = user_actor.send(
let user = match user_actor.send(
users_actor::GetUserRequest(user_id)
).await.unwrap().0.unwrap();
).await.unwrap().0 {
Some(u) => u,
None => {
return Err(ErrorInternalServerError("Could not extract user information!"));
}
};
Ok(CurrentUser(user))
})