tangled
alpha
login
or
join now
cherry.computer
/
website
My personal site
cherry.computer
htmx
tailwind
axum
askama
0
fork
atom
overview
issues
pulls
pipelines
fix: improve logging when last.fm returns an error
cherry.computer
1 year ago
8a5b5e0c
99cb2902
verified
This commit was signed with the committer's
known signature
.
cherry.computer
SSH Key Fingerprint:
SHA256:SIA77Ll0IpMb8Xd3RtaGT+PBIGIePhJJg5W2r6Td7cc=
+25
-6
3 changed files
expand all
collapse all
unified
split
server
src
main.rs
scrobble.rs
scrobble_monitor.rs
+4
-4
server/src/main.rs
···
86
interval.tick().await;
87
let new_template = match monitor.get_scrobble().await {
88
Ok(template) => template,
89
-
Err(err) => {
90
-
tracing::error!("failed to get data from last.fm: {err:?}");
91
continue;
92
}
93
};
···
101
102
let data = match new_template.render() {
103
Ok(data) => data,
104
-
Err(err) => {
105
-
tracing::error!("failed to render scrobble: {err:?}");
106
break;
107
}
108
};
···
86
interval.tick().await;
87
let new_template = match monitor.get_scrobble().await {
88
Ok(template) => template,
89
+
Err(error) => {
90
+
tracing::error!(?error, "failed to get data from last.fm");
91
continue;
92
}
93
};
···
101
102
let data = match new_template.render() {
103
Ok(data) => data,
104
+
Err(error) => {
105
+
tracing::error!(?error, "failed to render scrobble");
106
break;
107
}
108
};
+12
server/src/scrobble.rs
···
39
pub recent_tracks: RecentTracks,
40
}
41
0
0
0
0
0
0
0
0
0
0
0
0
42
#[derive(Template, Debug, Clone, PartialEq)]
43
#[template(path = "scrobble.html")]
44
pub struct ScrobblesTemplate {
···
39
pub recent_tracks: RecentTracks,
40
}
41
42
+
#[derive(Debug, Clone, Deserialize)]
43
+
pub struct Error {
44
+
pub message: String,
45
+
}
46
+
47
+
#[derive(Debug, Clone, Deserialize)]
48
+
#[serde(untagged)]
49
+
pub enum Response {
50
+
Scrobble(Scrobble),
51
+
Error(Error),
52
+
}
53
+
54
#[derive(Template, Debug, Clone, PartialEq)]
55
#[template(path = "scrobble.html")]
56
pub struct ScrobblesTemplate {
+9
-2
server/src/scrobble_monitor.rs
···
3
time::{Duration, Instant},
4
};
5
0
6
use reqwest::Client;
7
use tokio::sync::RwLock;
8
9
-
use crate::scrobble::{Scrobble, ScrobblesTemplate};
10
11
#[derive(Debug, Clone)]
12
struct CachedScrobble {
···
86
])
87
.send()
88
.await?;
89
-
Ok(response.json().await?)
0
0
0
0
0
0
90
}
91
}
···
3
time::{Duration, Instant},
4
};
5
6
+
use anyhow::anyhow;
7
use reqwest::Client;
8
use tokio::sync::RwLock;
9
10
+
use crate::scrobble::{Response, Scrobble, ScrobblesTemplate};
11
12
#[derive(Debug, Clone)]
13
struct CachedScrobble {
···
87
])
88
.send()
89
.await?;
90
+
let response: Response = response.json().await?;
91
+
match response {
92
+
Response::Scrobble(scrobble) => Ok(scrobble),
93
+
Response::Error(err) => {
94
+
Err(anyhow!("last.fm responded with an error: {}", err.message))
95
+
}
96
+
}
97
}
98
}