Skip to content

Commit

Permalink
Merge branch 'CHAOS-224-KHAOS-rewrite' into CHAOS-462-Organisations-CRUD
Browse files Browse the repository at this point in the history
  • Loading branch information
KavikaPalletenne authored Jun 28, 2024
2 parents 90702f6 + 1405e97 commit 0e57add
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
8 changes: 4 additions & 4 deletions backend/server/src/models/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ where
.get("auth_token")
.ok_or(ChaosError::NotLoggedInError)?;

let claims = decode_auth_token(token, decoding_key, jwt_validator)
.ok_or(ChaosError::NotLoggedInError)?;
let claims =
decode_auth_token(token, decoding_key, jwt_validator).ok_or(ChaosError::NotLoggedIn)?;

let pool = &app_state.db;
let possible_user = is_super_user(claims.sub, pool).await;
Expand All @@ -104,8 +104,8 @@ where
});
}
}

Err(ChaosError::UnauthorizedError)
Err(ChaosError::Unauthorized)
}
}

Expand Down
20 changes: 8 additions & 12 deletions backend/server/src/models/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use axum::response::{IntoResponse, Redirect, Response};
#[derive(thiserror::Error, Debug)]
pub enum ChaosError {
#[error("Not logged in")]
NotLoggedInError,
NotLoggedIn,

#[error("Not authorized")]
UnauthorizedError,
Unauthorized,

#[error("Forbidden operation")]
ForbiddenOperationError,

ForbiddenOperation,
#[error("Bad request")]
BadRequest,

Expand All @@ -42,20 +42,16 @@ pub enum ChaosError {
impl IntoResponse for ChaosError {
fn into_response(self) -> Response {
match self {
ChaosError::NotLoggedInError => Redirect::temporary("/auth/google").into_response(),
ChaosError::UnauthorizedError => {
(StatusCode::UNAUTHORIZED, "Unauthorized").into_response()
}
ChaosError::ForbiddenOperationError => {
(StatusCode::FORBIDDEN, "Forbidden operation").into_response()
}
ChaosError::NotLoggedIn => Redirect::temporary("/auth/google").into_response(),
ChaosError::Unauthorized => (StatusCode::UNAUTHORIZED, "Unauthorized").into_response(),
ChaosError::ForbiddenOperation => (StatusCode::FORBIDDEN, "Forbidden operation").into_response(),
ChaosError::BadRequest => (StatusCode::BAD_REQUEST, "Bad request").into_response(),
ChaosError::DatabaseError(db_error) => match db_error {
// We only care about the RowNotFound error, as others are miscellaneous DB errors.
sqlx::Error::RowNotFound => (StatusCode::NOT_FOUND, "Not found").into_response(),
_ => (StatusCode::INTERNAL_SERVER_ERROR, "Internal server error").into_response(),
},
_ => (StatusCode::INTERNAL_SERVER_ERROR, "Internal server error").into_response(),
_ => (StatusCode::INTERNAL_SERVER_ERROR, "Internal server error").into_response()
}
}
}

0 comments on commit 0e57add

Please sign in to comment.