summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKornel <kornel@geekhood.net>2020-02-29 01:22:03 +0000
committerKornel <kornel@geekhood.net>2020-02-29 01:22:03 +0000
commit88636d9df2a663f702e00bb4efcc447a929452de (patch)
tree6281f0e7cef3ffeae3eeebd4899333867cb82393
parent071336501a54e00661f3b108aca214476ccdde03 (diff)
Allow again some server errors for github responses
-rw-r--r--github_info/src/lib_github.rs24
-rw-r--r--github_v3/src/lib.rs8
-rw-r--r--server/Cargo.toml2
3 files changed, 23 insertions, 11 deletions
diff --git a/github_info/src/lib_github.rs b/github_info/src/lib_github.rs
index cb3e9cb..d4fce62 100644
--- a/github_info/src/lib_github.rs
+++ b/github_info/src/lib_github.rs
@@ -184,10 +184,19 @@ impl GitHub {
eprintln!("Cache near miss {}@{} vs {}", key.0, ver, key.1);
}
- let res = cb(&self.client).await?;
- let status = res.status();
- let headers = res.headers();
- eprintln!("Recvd {}@{} {:?} {:?}", key.0, key.1, status, headers);
+ let (status, res) = match cb(&self.client).await {
+ Ok(res) => {
+ let status = res.status();
+ let headers = res.headers();
+ eprintln!("Recvd {}@{} {:?} {:?}", key.0, key.1, status, headers);
+ (status, Some(res))
+ },
+ Err(github_v3::GHError::Response {status, message}) => {
+ eprintln!("GH Error {} {}", status, message.as_deref().unwrap_or("??"));
+ (status, None)
+ },
+ Err(e) => return Err(e.into()),
+ };
let non_parsable_body = match status {
StatusCode::ACCEPTED |
StatusCode::CREATED => return Err(Error::TryAgainLater),
@@ -204,8 +213,11 @@ impl GitHub {
StatusCode::MOVED_PERMANENTLY => true,
_ => status.is_success(),
};
- let body = res.obj().await;
- match body.map_err(|_| Error::NoBody).and_then(|stats| {
+ let body = match res {
+ Some(res) => Some(res.obj().await?),
+ None => None,
+ };
+ match body.ok_or(Error::NoBody).and_then(|stats| {
let dbg = format!("{:?}", stats);
Ok(postproc(serde_json::from_value(stats).map_err(|e| {
eprintln!("Error matching JSON: {}\n data: {}", e, dbg); e
diff --git a/github_v3/src/lib.rs b/github_v3/src/lib.rs
index 2f03e27..2ab19e7 100644
--- a/github_v3/src/lib.rs
+++ b/github_v3/src/lib.rs
@@ -187,7 +187,7 @@ impl ClientInner {
}
async fn error_for_response(res: reqwest::Response) -> GHError {
- let status = res.status().as_u16();
+ let status = res.status();
let mime = res.headers().get("content-type").and_then(|h| h.to_str().ok()).unwrap_or("");
GHError::Response {
status,
@@ -227,7 +227,7 @@ pub enum GHError {
#[error("Request error: {}", _0)]
Request(String),
#[error("{} ({})", message.as_deref().unwrap_or("HTTP error"), status)]
- Response { status: u16, message: Option<String> },
+ Response { status: StatusCode, message: Option<String> },
#[error("Internal error")]
Internal,
}
@@ -237,9 +237,9 @@ impl From<reqwest::Error> for GHError {
if e.is_timeout() {
return Self::Timeout;
}
- if let Some(s) = e.status() {
+ if let Some(status) = e.status() {
Self::Response {
- status: s.as_u16(),
+ status,
message: Some(e.to_string()),
}
} else {
diff --git a/server/Cargo.toml b/server/Cargo.toml
index 09d41c4..6a0c10c 100644
--- a/server/Cargo.toml
+++ b/server/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "crates-server"
-version = "0.12.4"
+version = "0.12.5"
authors = ["Kornel <kornel@geekhood.net>"]
edition = "2018"
description = "Crates.rs web server"