-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(turborepo): API Client Cleanup (#5084)
### Description I had this inside the HTTP cache PR, but it makes sense as a separate PR. Refactors the API client in the following ways: - Changes the retry logic to use try_clone from reqwest instead of the awkward (and unnecessarily general) `retry_future` function that relied on a closure that generates a Rust future. - Use a crate Error type with thiserror instead of anyhow. This is pretty standard. - Factor out some common logic into helper functions ### Testing Instructions Existing tests should suffice. Co-authored-by: --global <Nicholas Yang>
- Loading branch information
1 parent
945756e
commit 17de157
Showing
6 changed files
with
143 additions
and
165 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use std::backtrace::Backtrace; | ||
|
||
use reqwest::header::ToStrError; | ||
use thiserror::Error; | ||
|
||
use crate::CachingStatus; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum Error { | ||
#[error("Error making HTTP request: {0}")] | ||
ReqwestError(#[from] reqwest::Error), | ||
#[error("skipping HTTP Request, too many failures have occurred.\nLast error: {0}")] | ||
TooManyFailures(#[from] Box<reqwest::Error>), | ||
#[error("Error parsing header: {0}")] | ||
InvalidHeader(#[from] ToStrError), | ||
#[error("Error parsing URL: {0}")] | ||
InvalidUrl(#[from] url::ParseError), | ||
#[error("unknown caching status: {0}")] | ||
UnknownCachingStatus(String, #[backtrace] Backtrace), | ||
#[error("unknown status {code}: {message}")] | ||
UnknownStatus { | ||
code: String, | ||
message: String, | ||
#[backtrace] | ||
backtrace: Backtrace, | ||
}, | ||
#[error("{message}")] | ||
CacheDisabled { | ||
status: CachingStatus, | ||
message: String, | ||
}, | ||
} | ||
|
||
pub type Result<T> = std::result::Result<T, Error>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.