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?; surreal_db_client.apply_migrations().await?;
let app_state = ApiState { let app_state = Self {
db: surreal_db_client.clone(), db: surreal_db_client.clone(),
config: config.clone(), config: config.clone(),
}; };

View File

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

View File

@@ -35,7 +35,7 @@ fn extract_api_key(request: &Request) -> Option<String> {
.headers() .headers()
.get("Authorization") .get("Authorization")
.and_then(|v| v.to_str().ok()) .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) .map(String::from)
} }