Skip to content

Commit 7239a42

Browse files
author
Christoph Siedentop
committed
The user-agent was missing.
Also some minor cleanup (Table and using `error_for_status()`)
1 parent 4193144 commit 7239a42

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

examples/github/examples/github.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,21 @@ fn main() -> Result<(), anyhow::Error> {
5151
name: name.to_string(),
5252
});
5353

54-
let client = reqwest::blocking::Client::new();
54+
let client = reqwest::blocking::Client::builder()
55+
.user_agent("graphql-rust/0.9.0")
56+
.build()?;
5557

5658
let res = client
5759
.post("https://api.github.com/graphql")
5860
.bearer_auth(config.github_api_token)
5961
.json(&q)
6062
.send()?;
6163

64+
res.error_for_status_ref()?;
65+
6266
let response_body: Response<repo_view::ResponseData> = res.json()?;
6367
info!("{:?}", response_body);
6468

65-
if let Some(errors) = response_body.errors {
66-
println!("there are errors:");
67-
68-
for error in &errors {
69-
println!("{:?}", error);
70-
}
71-
}
72-
7369
let response_data: repo_view::ResponseData = response_body.data.expect("missing response data");
7470

7571
let stars: Option<i64> = response_data
@@ -80,8 +76,8 @@ fn main() -> Result<(), anyhow::Error> {
8076
println!("{}/{} - 🌟 {}", owner, name, stars.unwrap_or(0),);
8177

8278
let mut table = prettytable::Table::new();
83-
84-
table.add_row(row!(b => "issue", "comments"));
79+
table.set_format(*prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
80+
table.set_titles(row!(b => "issue", "comments"));
8581

8682
for issue in &response_data
8783
.repository

0 commit comments

Comments
 (0)