mirror of
https://github.com/danbulant/Portfolio
synced 2026-07-06 03:20:53 +00:00
feat: return 401 error instead of panicking
This commit is contained in:
parent
8656a82ef8
commit
1bfc8f68c2
3 changed files with 5 additions and 2 deletions
|
|
@ -8,6 +8,8 @@ pub enum ServiceError {
|
||||||
InvalidApplicationId,
|
InvalidApplicationId,
|
||||||
#[error("Invalid credentials")]
|
#[error("Invalid credentials")]
|
||||||
InvalidCredentials,
|
InvalidCredentials,
|
||||||
|
#[error("Unauthorized")]
|
||||||
|
Unauthorized,
|
||||||
#[error("Forbidden")]
|
#[error("Forbidden")]
|
||||||
Forbidden,
|
Forbidden,
|
||||||
#[error("Session expired, please login agai")]
|
#[error("Session expired, please login agai")]
|
||||||
|
|
@ -65,6 +67,7 @@ impl ServiceError {
|
||||||
match self {
|
match self {
|
||||||
ServiceError::InvalidApplicationId => 400,
|
ServiceError::InvalidApplicationId => 400,
|
||||||
ServiceError::InvalidCredentials => 401,
|
ServiceError::InvalidCredentials => 401,
|
||||||
|
ServiceError::Unauthorized => 401,
|
||||||
ServiceError::Forbidden => 403,
|
ServiceError::Forbidden => 403,
|
||||||
ServiceError::ExpiredSession => 401,
|
ServiceError::ExpiredSession => 401,
|
||||||
ServiceError::JwtError => 500,
|
ServiceError::JwtError => 500,
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ impl AdminService {
|
||||||
pub async fn auth(db: &DbConn, session_uuid: Uuid) -> Result<admin::Model, ServiceError> {
|
pub async fn auth(db: &DbConn, session_uuid: Uuid) -> Result<admin::Model, ServiceError> {
|
||||||
match SessionService::auth_user_session(db, session_uuid).await? {
|
match SessionService::auth_user_session(db, session_uuid).await? {
|
||||||
AdminUser::Admin(admin) => Ok(admin),
|
AdminUser::Admin(admin) => Ok(admin),
|
||||||
AdminUser::Candidate(_) => unreachable!(),
|
AdminUser::Candidate(_) => Err(ServiceError::Unauthorized),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -215,7 +215,7 @@ impl CandidateService {
|
||||||
match SessionService::auth_user_session(db, session_uuid).await {
|
match SessionService::auth_user_session(db, session_uuid).await {
|
||||||
Ok(user) => match user {
|
Ok(user) => match user {
|
||||||
AdminUser::Candidate(candidate) => Ok(candidate),
|
AdminUser::Candidate(candidate) => Ok(candidate),
|
||||||
AdminUser::Admin(_) => unreachable!(),
|
AdminUser::Admin(_) => Err(ServiceError::Unauthorized),
|
||||||
},
|
},
|
||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue