main: add better error reporting for /bandcamp

This commit is contained in:
2026-06-08 10:27:59 +02:00
parent 50c55f0887
commit b53aa0fa06
+15 -13
View File
@@ -386,10 +386,13 @@ impl App {
let arg = parts.next().unwrap_or(""); let arg = parts.next().unwrap_or("");
match command { match command {
"/bandcamp" => { "/bandcamp" => {
self.add_bandcamp_artifact(arg).await; if let Err(err) = self.add_bandcamp_artifact(arg).await {
self.sys_message_sink.send(format!("Added Bandcamp artifact from {}", arg)).await.unwrap(); self.sys_message_sink.send(format!("Failed to fetch artifact: {:?}", err)).await.unwrap();
self.next_actions.push(ConversationEntry::ShipComputer(format!("Incoming transmission from {}", arg))); } else {
self.regenerate_responses(); self.sys_message_sink.send(format!("Added Bandcamp artifact from {}", arg)).await.unwrap();
self.next_actions.push(ConversationEntry::ShipComputer(format!("Incoming transmission from {}", arg)));
self.regenerate_responses();
}
}, },
"/episode" => { "/episode" => {
if let Ok(episode_number) = arg.trim().parse::<u32>() { if let Ok(episode_number) = arg.trim().parse::<u32>() {
@@ -507,15 +510,14 @@ impl App {
} }
} }
async fn add_bandcamp_artifact(&mut self, url: &str) { async fn add_bandcamp_artifact(&mut self, url: &str) -> Result<(), BandcampError> {
if let Ok(album) = bandcamp::album_from_url(url).await { let album = bandcamp::album_from_url(url).await?;
let result: BandcampResult = album.into(); let result: BandcampResult = album.into();
let json = serde_json::to_string(&result).unwrap(); let json = serde_json::to_string(&result)?;
self.direction.artifacts.push(json); self.direction.artifacts.push(json);
self.sys_message_sink.send("Added bandcamp album".into()).await.unwrap(); self.sys_message_sink.send("Added bandcamp album".into()).await.unwrap();
} else {
self.sys_message_sink.send("Could not fetch bandcamp data! Is that a proper URL?".into()).await.unwrap(); Ok(())
}
} }
async fn speak(&mut self, text: String) { async fn speak(&mut self, text: String) {