mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Return HttpClientError for status code <> 200
This commit is contained in:
parent
e1b273b8a1
commit
a73e05837e
1 changed files with 10 additions and 6 deletions
|
@ -20,6 +20,8 @@ pub enum HttpClientError {
|
|||
Request(hyper::Error),
|
||||
#[error("could not read response: {0}")]
|
||||
Response(hyper::Error),
|
||||
#[error("status code: {0}")]
|
||||
NotOK(u16),
|
||||
#[error("could not build proxy connector: {0}")]
|
||||
ProxyBuilder(#[from] std::io::Error),
|
||||
}
|
||||
|
@ -44,19 +46,20 @@ impl HttpClient {
|
|||
}
|
||||
|
||||
pub async fn request(&self, mut req: Request<Body>) -> Result<Response<Body>, HttpClientError> {
|
||||
trace!("Requesting {:?}", req.uri().to_string());
|
||||
|
||||
let connector = HttpsConnector::with_native_roots();
|
||||
let uri = req.uri().clone();
|
||||
|
||||
let headers_mut = req.headers_mut();
|
||||
headers_mut.insert(
|
||||
"User-Agent",
|
||||
// Some features like lyrics are version-gated and require a "real" version string.
|
||||
// Some features like lyrics are version-gated and require an official version string.
|
||||
HeaderValue::from_str("Spotify/8.6.80 iOS/13.5 (iPhone11,2)")?,
|
||||
);
|
||||
|
||||
let response = if let Some(url) = &self.proxy {
|
||||
let uri = url.to_string().parse()?;
|
||||
let proxy = Proxy::new(Intercept::All, uri);
|
||||
let proxy_uri = url.to_string().parse()?;
|
||||
let proxy = Proxy::new(Intercept::All, proxy_uri);
|
||||
let proxy_connector = ProxyConnector::from_proxy(connector, proxy)?;
|
||||
|
||||
Client::builder()
|
||||
|
@ -73,8 +76,9 @@ impl HttpClient {
|
|||
};
|
||||
|
||||
if let Ok(response) = &response {
|
||||
if response.status() != StatusCode::OK {
|
||||
debug!("{} returned status {}", uri, response.status());
|
||||
let status = response.status();
|
||||
if status != StatusCode::OK {
|
||||
return Err(HttpClientError::NotOK(status.into()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue