chore: clippy api-router

This commit is contained in:
Per Stark
2025-10-16 20:33:57 +02:00
parent 99b88c3063
commit ab68bccb80
3 changed files with 11 additions and 11 deletions

View File

@@ -23,7 +23,7 @@ impl ApiState {
surreal_db_client.apply_migrations().await?;
let app_state = ApiState {
let app_state = Self {
db: surreal_db_client.clone(),
config: config.clone(),
};

View File

@@ -27,40 +27,40 @@ impl From<AppError> for ApiError {
match err {
AppError::Database(_) | AppError::OpenAI(_) => {
tracing::error!("Internal error: {:?}", err);
ApiError::InternalError("Internal server error".to_string())
Self::InternalError("Internal server error".to_string())
}
AppError::NotFound(msg) => ApiError::NotFound(msg),
AppError::Validation(msg) => ApiError::ValidationError(msg),
AppError::Auth(msg) => ApiError::Unauthorized(msg),
_ => ApiError::InternalError("Internal server error".to_string()),
AppError::NotFound(msg) => Self::NotFound(msg),
AppError::Validation(msg) => Self::ValidationError(msg),
AppError::Auth(msg) => Self::Unauthorized(msg),
_ => Self::InternalError("Internal server error".to_string()),
}
}
}
impl IntoResponse for ApiError {
fn into_response(self) -> Response {
let (status, error_response) = match self {
ApiError::InternalError(message) => (
Self::InternalError(message) => (
StatusCode::INTERNAL_SERVER_ERROR,
ErrorResponse {
error: message,
status: "error".to_string(),
},
),
ApiError::ValidationError(message) => (
Self::ValidationError(message) => (
StatusCode::BAD_REQUEST,
ErrorResponse {
error: message,
status: "error".to_string(),
},
),
ApiError::NotFound(message) => (
Self::NotFound(message) => (
StatusCode::NOT_FOUND,
ErrorResponse {
error: message,
status: "error".to_string(),
},
),
ApiError::Unauthorized(message) => (
Self::Unauthorized(message) => (
StatusCode::UNAUTHORIZED,
ErrorResponse {
error: message,

View File

@@ -35,7 +35,7 @@ fn extract_api_key(request: &Request) -> Option<String> {
.headers()
.get("Authorization")
.and_then(|v| v.to_str().ok())
.and_then(|auth| auth.strip_prefix("Bearer ").map(|s| s.trim()))
.and_then(|auth| auth.strip_prefix("Bearer ").map(str::trim))
})
.map(String::from)
}