feat: connect to github step
This commit is contained in:
11
src/api.rs
11
src/api.rs
@@ -58,6 +58,7 @@ impl QueryContext {
|
||||
.request(method, format!("{}{}", self.github.base_url, url))
|
||||
.header("Accept", "application/vnd.github+json")
|
||||
.header("X-GitHub-Api-Version", "2026-03-10")
|
||||
.header("User-Agent", "kennethnym")
|
||||
.bearer_auth(&auth.access_token))
|
||||
}
|
||||
}
|
||||
@@ -83,11 +84,19 @@ where
|
||||
let status = res.status().clone();
|
||||
let data = res.bytes().await?;
|
||||
|
||||
println!("[query] RES {:?} {:?}", status, str::from_utf8(&data));
|
||||
|
||||
if status.is_success() {
|
||||
serde_json::from_slice::<T>(&data).map_err(|e| e.into())
|
||||
} else {
|
||||
serde_json::from_slice::<GithubError>(&data)
|
||||
.map_err(|e| e.into())
|
||||
.and_then(|e| Err(Error::Github(e)))
|
||||
.and_then(|e| {
|
||||
println!(
|
||||
"[api parse error] invalid json, received: {:?}",
|
||||
str::from_utf8(&data),
|
||||
);
|
||||
Err(Error::Github(e))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user