-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle status for response #10
Conversation
src/clients.rs
Outdated
@@ -7,6 +7,15 @@ use crate::types::{BundleUploadLocation, Repo}; | |||
pub const TRUNK_API_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(30); | |||
pub const TRUNK_API_TOKEN_HEADER: &str = "x-api-token"; | |||
|
|||
fn handle_upload_bundle_error_logs(status: Option<reqwest::StatusCode>) { | |||
log::error!("Failed to create bundle upload. Status: {:?}", status); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should keep the output concise to a single helpful error message.
src/clients.rs
Outdated
return Err(anyhow::anyhow!(e).context("Failed to create bundle upload")); | ||
} | ||
}; | ||
|
||
if resp.status() != reqwest::StatusCode::OK { | ||
handle_upload_bundle_error_logs(Some(resp.status())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would consider only appending information to context here and moving error logging into a common error-handling location inside main.rs. Otherwise, it seems like we might be double-logging.
src/main.rs
Outdated
@@ -68,7 +68,7 @@ const DEFAULT_API_ADDRESS: &str = "https://api.trunk.io/v1/metrics/createBundleU | |||
// This will give us 8ms, 64ms, 512ms, 4096ms, 32768ms | |||
const RETRY_BASE_MS: u64 = 8; | |||
const RETRY_FACTOR: u64 = 1; | |||
const RETRY_COUNT: usize = 5; | |||
const RETRY_COUNT: usize = 3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why we need to retry 5 times. When making a request with incorrect token, this takes 40 seconds to complete and log the error. With retry 3 times, it only takes a couple of seconds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we want to reduce from 40s to 3s though? That's a point of retrying – give backend time to auto-resolve some transient issue.
No description provided.