fix: handle channel_rss not found
This commit is contained in:
parent
d4d029c3ce
commit
de118c59c4
3 changed files with 30 additions and 2 deletions
|
|
@ -17,7 +17,13 @@ impl RustyPipeQuery {
|
|||
let xml = self
|
||||
.client
|
||||
.http_request_txt(self.client.inner.http.get(&url).build()?)
|
||||
.await?;
|
||||
.await
|
||||
.map_err(|e| match e {
|
||||
Error::HttpStatus(404) => Error::Extraction(ExtractionError::ContentUnavailable(
|
||||
"Channel not found".into(),
|
||||
)),
|
||||
_ => e,
|
||||
})?;
|
||||
|
||||
match quick_xml::de::from_str::<response::ChannelRss>(&xml) {
|
||||
Ok(feed) => Ok(feed.into()),
|
||||
|
|
|
|||
|
|
@ -505,7 +505,14 @@ impl RustyPipe {
|
|||
/// Execute the given http request, returning an error in case of a
|
||||
/// non-successful status code.
|
||||
async fn http_request_estatus(&self, request: Request) -> Result<Response> {
|
||||
Ok(self.http_request(request).await?.error_for_status()?)
|
||||
let res = self.http_request(request).await?;
|
||||
let status = res.status();
|
||||
|
||||
if status.is_client_error() || status.is_server_error() {
|
||||
Err(Error::HttpStatus(status.into()))
|
||||
} else {
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
/// Execute the given http request, returning the response body as a string.
|
||||
|
|
|
|||
|
|
@ -921,6 +921,21 @@ async fn get_channel_rss() {
|
|||
assert!(!channel.videos.is_empty());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_channel_rss_not_found() {
|
||||
let rp = RustyPipe::builder().strict().build();
|
||||
let err = rp
|
||||
.query()
|
||||
.channel_rss("UCHnyfMqiRRG1u-2MsSQLbXZ")
|
||||
.await
|
||||
.unwrap_err();
|
||||
|
||||
assert!(matches!(
|
||||
err,
|
||||
Error::Extraction(ExtractionError::ContentUnavailable(_))
|
||||
));
|
||||
}
|
||||
|
||||
//#SEARCH
|
||||
|
||||
#[tokio::test]
|
||||
|
|
|
|||
Reference in a new issue