diff --git a/api-router/src/api_state.rs b/api-router/src/api_state.rs index 0ae3bd6..4f271d7 100644 --- a/api-router/src/api_state.rs +++ b/api-router/src/api_state.rs @@ -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(), }; diff --git a/api-router/src/error.rs b/api-router/src/error.rs index 9beeb72..bb2672b 100644 --- a/api-router/src/error.rs +++ b/api-router/src/error.rs @@ -27,40 +27,40 @@ impl From 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, diff --git a/api-router/src/middleware_api_auth.rs b/api-router/src/middleware_api_auth.rs index 13b6c28..6c58697 100644 --- a/api-router/src/middleware_api_auth.rs +++ b/api-router/src/middleware_api_auth.rs @@ -35,7 +35,7 @@ fn extract_api_key(request: &Request) -> Option { .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) }