Skip to content

Commit

Permalink
feature: Use error_for_status (#3898)
Browse files Browse the repository at this point in the history
Instead of manually handling the error, check the HTTP code and error
accordingly.
  • Loading branch information
NicholasLYang authored Feb 23, 2023
1 parent e1be5cd commit 6e8866e
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions crates/turborepo-lib/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ impl APIClient {

request_builder.send()
})
.await?;
.await?
.error_for_status()?;

response.json().await.map_err(|err| {
anyhow!(
Expand All @@ -138,7 +139,8 @@ impl APIClient {

request_builder.send()
})
.await?;
.await?
.error_for_status()?;

response.json().await.map_err(|err| {
anyhow!(
Expand All @@ -151,17 +153,16 @@ impl APIClient {
}

pub async fn get_team(&self, token: &str, team_id: &str) -> Result<Option<Team>> {
let response = {
let request_builder = self
.client
.get(self.make_url("/v2/team"))
.query(&[("teamId", team_id)])
.header("User-Agent", USER_AGENT.clone())
.header("Content-Type", "application/json")
.header("Authorization", format!("Bearer {}", token));
request_builder.send()
}
.await?;
let response = self
.client
.get(self.make_url("/v2/team"))
.query(&[("teamId", team_id)])
.header("User-Agent", USER_AGENT.clone())
.header("Content-Type", "application/json")
.header("Authorization", format!("Bearer {}", token))
.send()
.await?
.error_for_status()?;

response.json().await.map_err(|err| {
anyhow!(
Expand Down Expand Up @@ -197,7 +198,8 @@ impl APIClient {

request_builder.send()
})
.await?;
.await?
.error_for_status()?;

response.json().await.map_err(|err| {
anyhow!(
Expand All @@ -220,7 +222,8 @@ impl APIClient {

request_builder.send()
})
.await?;
.await?
.error_for_status()?;

let verification_response: VerificationResponse = response.json().await.map_err(|err| {
anyhow!(
Expand Down

0 comments on commit 6e8866e

Please sign in to comment.