Timeout when fetching feeds
This commit is contained in:
parent
7ecf598aa8
commit
c8301d14e1
@ -1,4 +1,5 @@
|
|||||||
use feed_rs;
|
use feed_rs;
|
||||||
|
use std::time::Duration;
|
||||||
use tracing::{error, info};
|
use tracing::{error, info};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
@ -8,9 +9,22 @@ pub struct FeedError;
|
|||||||
pub async fn fetch_feed(url: &Url) -> Result<feed_rs::model::Feed, FeedError> {
|
pub async fn fetch_feed(url: &Url) -> Result<feed_rs::model::Feed, FeedError> {
|
||||||
info!("Making a request to fetch feed `{url}`");
|
info!("Making a request to fetch feed `{url}`");
|
||||||
|
|
||||||
|
// Create a client with a 10 second timeout
|
||||||
|
let client = reqwest::Client::builder()
|
||||||
|
.timeout(Duration::from_secs(10))
|
||||||
|
.build()
|
||||||
|
.map_err(|e| {
|
||||||
|
error!("Failed to create HTTP client: {}", e);
|
||||||
|
FeedError
|
||||||
|
})?;
|
||||||
|
|
||||||
// Fetch the feed content
|
// Fetch the feed content
|
||||||
let response = reqwest::get(url.as_ref()).await.map_err(|e| {
|
let response = client.get(url.as_ref()).send().await.map_err(|e| {
|
||||||
|
if e.is_timeout() {
|
||||||
|
error!("Request timed out after 10 seconds: {}", e);
|
||||||
|
} else {
|
||||||
error!("Failed to fetch feed: {}", e);
|
error!("Failed to fetch feed: {}", e);
|
||||||
|
}
|
||||||
FeedError
|
FeedError
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user