Revert "add tracing + custom error type"

This reverts commit 4702017914.
This commit is contained in:
Philipp Hofer
2025-10-16 11:53:06 +02:00
parent 4702017914
commit 5ee6a679c5
4 changed files with 11 additions and 44 deletions

13
Cargo.lock generated
View File

@@ -726,7 +726,6 @@ dependencies = [
"serde_json",
"thiserror",
"tokio",
"tracing",
]
[[package]]
@@ -1292,21 +1291,9 @@ checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0"
dependencies = [
"log",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
]
[[package]]
name = "tracing-attributes"
version = "0.1.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tracing-core"
version = "0.1.34"

View File

@@ -11,4 +11,3 @@ serde_json = "1"
chrono = "0.4"
quick-xml = "0.38"
thiserror = "2"
tracing = "0.1"

View File

@@ -6,7 +6,6 @@ use serde_json::Value;
use std::sync::Arc;
use thiserror::Error;
use tokio::{net::TcpListener, sync::RwLock};
use tracing::warn;
pub async fn start(
title: String,
@@ -27,15 +26,10 @@ pub async fn start(
}
#[derive(Error, Debug)]
enum FetchError {
#[error("error fetching url")]
Fetching(reqwest::Error),
#[error("error parsing json")]
JsonParsing(reqwest::Error),
}
enum FetchError {}
trait Feed {
async fn fetch(&mut self) -> Result<(), FetchError>;
async fn fetch(&mut self) -> Result<(), Box<dyn std::error::Error>>;
}
#[cfg(test)]
@@ -75,7 +69,7 @@ impl rss::ToRss for TestFeed {
#[cfg(test)]
impl Feed for TestFeed {
async fn fetch(&mut self) -> Result<(), FetchError> {
async fn fetch(&mut self) -> Result<(), Box<dyn std::error::Error>> {
self.amount_fetch_calls += 1;
Ok(())
}
@@ -90,7 +84,7 @@ struct LiveFeed {
}
impl Feed for LiveFeed {
async fn fetch(&mut self) -> Result<(), FetchError> {
async fn fetch(&mut self) -> Result<(), Box<dyn std::error::Error>> {
let broadcasts = self.get_all_broadcasts().await?;
for broadcast in broadcasts {
@@ -138,17 +132,12 @@ impl LiveFeed {
self.episodes.iter().any(|e| e.url == url)
}
async fn get_all_broadcasts(&self) -> Result<Vec<String>, FetchError> {
async fn get_all_broadcasts(&self) -> Result<Vec<String>, Box<dyn std::error::Error>> {
// List of broadcasts: https://audioapi.orf.at/oe1/api/json/current/broadcasts
//
// ^ contains link, e.g. https://audioapi.orf.at/oe1/api/json/4.0/broadcast/797577/20250611
let url = "https://audioapi.orf.at/oe1/api/json/current/broadcasts";
let data: Value = reqwest::get(url)
.await
.map_err(FetchError::Fetching)?
.json()
.await
.map_err(FetchError::JsonParsing)?;
let data: Value = reqwest::get(url).await?.json().await?;
let mut ret: Vec<String> = Vec::new();
@@ -156,19 +145,13 @@ impl LiveFeed {
for day in days {
if let Some(broadcasts) = day["broadcasts"].as_array() {
for broadcast in broadcasts {
let Some(title) = broadcast["title"].as_str() else {
warn!("Broadcast has no 'title' attribute, skipping broadcast");
continue;
};
let Some(href) = broadcast["href"].as_str() else {
warn!("Broadcast has no 'href' attribute, skipping broadcast");
continue;
};
if self.filter_titles.is_empty()
|| self.filter_titles.contains(&title.into())
|| self
.filter_titles
.contains(&broadcast["title"].as_str().unwrap().into())
{
{
ret.push(href.into());
ret.push(broadcast["href"].as_str().unwrap().into());
}
}
}

View File

@@ -4,9 +4,7 @@ use reqwest::header;
use std::sync::Arc;
use tokio::{net::TcpListener, sync::RwLock};
async fn stream_handler<T: Feed + ToRss + Send>(
State(state): State<Arc<RwLock<T>>>,
) -> impl IntoResponse {
async fn stream_handler<T: Feed + ToRss>(State(state): State<Arc<RwLock<T>>>) -> impl IntoResponse {
state.write().await.fetch().await.unwrap();
let content = state.read().await.to_rss();