Skip to content

Commit 61680eb

Browse files
committed
Modifies HTTP request response debug printing to make use of the -d | --debug CLI flag.
1 parent 584b6f2 commit 61680eb

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/lib.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,30 @@ pub fn run(cli: &Cli) {
136136
.body(json)
137137
.send();
138138

139-
println!("Response: {:#?}", res);
139+
match res {
140+
Ok(response) => {
141+
match cli.debug {
142+
true => println!("Response from Ambi backend: {:#?}", response),
143+
false => println!("Response from Ambi backend: {:?}", response.status().as_str())
144+
}
145+
}
146+
Err(e) => {
147+
match cli.debug {
148+
// Print out the entire reqwest::Error for verbose debugging
149+
true => eprintln!("Response error from Ambi backend: {:?}", e),
150+
// Keep the error reports more succinct
151+
false => {
152+
if e.is_request() {
153+
eprintln!("Response error from Ambi backend: request error");
154+
} else if e.is_timeout() {
155+
eprintln!("Response error from Ambi backend: request timed out");
156+
} else {
157+
eprintln!("Response error from Ambi backend: specific error type unknown");
158+
}
159+
}
160+
}
161+
}
162+
}
140163
}
141164

142165
#[cfg(test)]

0 commit comments

Comments
 (0)