Skip to content

Commit ef737ad

Browse files
committed
feat: add circuit breaker to github client, improve env var handling
Also changed the error handling, API cache structure, removed some redundant tests & methods
1 parent a0352de commit ef737ad

File tree

8 files changed

+664
-193
lines changed

8 files changed

+664
-193
lines changed

Cargo.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ tokio-stream = "0.1.17"
4040
foyer = { version = "0.18.0", features = ["serde"] }
4141
bincode = "2.0.1"
4242
sha256 = "1.6.0"
43+
failsafe = "1.3.0"
4344

4445
[build-dependencies]
4546
phf_codegen = "0.12.1"

src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn format_svg_template(
8888
/// Result indicating success or failure of card generation
8989
pub async fn run(cli: Cli) -> Result<()> {
9090
let repo_path = cli.repository.as_ref().unwrap();
91-
let repo = github::get_repository_info(repo_path, cli.token).await?;
91+
let repo = github::GITHUB_CLIENT.get_repository_info(repo_path).await?;
9292

9393
let output_path = match cli.output {
9494
Some(path) => path,

src/errors.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ pub enum GitHubError {
6868
/// Authentication error
6969
#[error("Authentication failed: {0}")]
7070
AuthError(String),
71+
72+
/// Circuit breaker open
73+
#[error("Circuit breaker open")]
74+
CircuitBreakerOpen,
7175
}
7276

7377
/// Image generation specific errors
@@ -147,6 +151,7 @@ impl From<GitHubError> for axum::http::StatusCode {
147151
GitHubError::NetworkError => axum::http::StatusCode::BAD_GATEWAY,
148152
GitHubError::InvalidFormat(_) => axum::http::StatusCode::BAD_REQUEST,
149153
GitHubError::AuthError(_) => axum::http::StatusCode::UNAUTHORIZED,
154+
GitHubError::CircuitBreakerOpen => axum::http::StatusCode::SERVICE_UNAVAILABLE,
150155
}
151156
}
152157
}

0 commit comments

Comments
 (0)