Skip to content

Commit

Permalink
cli: improve error message on expired token
Browse files Browse the repository at this point in the history
Slightly improve the error message when an expired token is used. Old experience:

thread 'main' panicked at src/fetch.rs:95:10:
called `Result::unwrap()` on an `Err` value: reqwest::Error { kind: Decode, source: Error("missing field `data`", line: 1, column: 40) }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

New experience:

thread 'main' panicked at src/fetch.rs:98:13:
Request to Gitlab failed: HTTP status client error (401 Unauthorized) for url (https://gitlab.vpn.cyberus-technology.de/api/graphql)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

It's not perfect and a better solution would be proper error handling
with anyhow. But this would have already poked me in the right
direction.
  • Loading branch information
blitz committed Dec 17, 2024
1 parent 0a15f14 commit c813f47
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,19 @@ fn fetch_result(
let url = format!("https://{host}/api/graphql", host = host);
let client = Client::new();

client
match client
.post(url)
.header(AUTHORIZATION, authorization)
.json(&payload)
.send()
.unwrap()
.json::<Response>()
.unwrap()
.error_for_status()
{
Ok(response) => response.json::<Response>().unwrap(),
Err(err) => {
panic!("Request to Gitlab failed: {err}")
}
}
}

/// Fetches all results from the API with pagination in mind.
Expand Down

0 comments on commit c813f47

Please sign in to comment.