mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-19 06:21:15 +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,
|
||||
#[error("Invalid credentials")]
|
||||
InvalidCredentials,
|
||||
#[error("Unauthorized")]
|
||||
Unauthorized,
|
||||
#[error("Forbidden")]
|
||||
Forbidden,
|
||||
#[error("Session expired, please login agai")]
|
||||
|
|
@ -65,6 +67,7 @@ impl ServiceError {
|
|||
match self {
|
||||
ServiceError::InvalidApplicationId => 400,
|
||||
ServiceError::InvalidCredentials => 401,
|
||||
ServiceError::Unauthorized => 401,
|
||||
ServiceError::Forbidden => 403,
|
||||
ServiceError::ExpiredSession => 401,
|
||||
ServiceError::JwtError => 500,
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ impl AdminService {
|
|||
pub async fn auth(db: &DbConn, session_uuid: Uuid) -> Result<admin::Model, ServiceError> {
|
||||
match SessionService::auth_user_session(db, session_uuid).await? {
|
||||
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 {
|
||||
Ok(user) => match user {
|
||||
AdminUser::Candidate(candidate) => Ok(candidate),
|
||||
AdminUser::Admin(_) => unreachable!(),
|
||||
AdminUser::Admin(_) => Err(ServiceError::Unauthorized),
|
||||
},
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue