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

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();