Skip to content

Commit

Permalink
refactor(core/result): add NotAuthenticated error which is distinct f…
Browse files Browse the repository at this point in the history
…rom InvalidCredentials
  • Loading branch information
insertish committed Sep 29, 2024
1 parent 916f47e commit 4fd66b2
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/core/database/src/models/channel_webhooks/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Webhook {
if self.token.as_deref() == Some(token) {
Ok(())
} else {
Err(create_error!(InvalidCredentials))
Err(create_error!(NotAuthenticated))
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/core/database/src/models/users/axum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl FromRequestParts<Database> for User {
let session = db.fetch_session_by_token(session_token).await?;
db.fetch_user(&session.user_id).await
} else {
Err(create_error!(InvalidCredentials))
Err(create_error!(NotAuthenticated))
}
}
}
1 change: 1 addition & 0 deletions crates/core/result/src/axum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ impl IntoResponse for Error {
ErrorType::InvalidCredentials => StatusCode::UNAUTHORIZED,
ErrorType::InvalidProperty => StatusCode::BAD_REQUEST,
ErrorType::InvalidSession => StatusCode::UNAUTHORIZED,
ErrorType::NotAuthenticated => StatusCode::UNAUTHORIZED,
ErrorType::DuplicateNonce => StatusCode::CONFLICT,
ErrorType::VosoUnavailable => StatusCode::BAD_REQUEST,
ErrorType::NotFound => StatusCode::NOT_FOUND,
Expand Down
1 change: 1 addition & 0 deletions crates/core/result/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ pub enum ErrorType {
InvalidCredentials,
InvalidProperty,
InvalidSession,
NotAuthenticated,
DuplicateNonce,
NotFound,
NoEffect,
Expand Down
1 change: 1 addition & 0 deletions crates/core/result/src/rocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl<'r> Responder<'r, 'static> for Error {
ErrorType::InvalidCredentials => Status::Unauthorized,
ErrorType::InvalidProperty => Status::BadRequest,
ErrorType::InvalidSession => Status::Unauthorized,
ErrorType::NotAuthenticated => Status::Unauthorized,
ErrorType::DuplicateNonce => Status::Conflict,
ErrorType::VosoUnavailable => Status::BadRequest,
ErrorType::NotFound => Status::NotFound,
Expand Down

0 comments on commit 4fd66b2

Please sign in to comment.