-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.rs
35 lines (30 loc) · 929 Bytes
/
client.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use reqwest::{Client, ClientBuilder};
use ::log::{debug, trace};
use crate::package::{NAME, VERSION};
pub fn client() -> Client {
ClientBuilder::new()
.user_agent(format!("{NAME}/{VERSION}"))
.build()
.unwrap()
}
pub async fn send_request(request: Result<reqwest::Request, reqwest::Error>) {
let request = match request {
Ok(request) => request,
Err(err) => {
debug!("error creating request: {}", err);
return;
}
};
match client().execute(request.try_clone().unwrap()).await {
Ok(response) => {
if !response.status().is_success() {
debug!("request failed with status: {}", response.status());
} else {
trace!("request successful: {}", request.url());
}
}
Err(err) => {
debug!("error sending request: {:?}", err);
}
};
}