tangled
alpha
login
or
join now
vielle.dev
/
site
0
fork
atom
Personal Site
0
fork
atom
overview
issues
pulls
pipelines
Add sane error handling for SSR mode
vielle.dev
7 months ago
829a42e3
cfec434d
verified
This commit was signed with the committer's
known signature
.
vielle.dev
SSH Key Fingerprint:
SHA256:/4bvxqoEh9iMdjAPgcgAgXKZZQTROL3ULiPt6nH9RSs=
+32
-35
1 changed file
expand all
collapse all
unified
split
src
components
playing
NowPlaying.astro
+32
-35
src/components/playing/NowPlaying.astro
···
18
18
return err;
19
19
});
20
20
21
21
+
if (track instanceof SpotifyError)
22
22
+
console.error("Encountered spotify error:", track);
23
23
+
21
24
const dataTrack = (
22
25
t: typeof track,
23
26
): t is Exclude<typeof track, SpotifyError | null> =>
24
24
-
!(track instanceof SpotifyError || !track);
27
27
+
!(t instanceof SpotifyError || !t);
25
28
---
26
29
30
30
+
{
31
31
+
track instanceof SpotifyError && (
32
32
+
<script
33
33
+
set:html={`console.error("Failed to load nowPlaying. See server console for reason.")`}
34
34
+
/>
35
35
+
)
36
36
+
}
37
37
+
27
38
<section
28
39
class="playing"
29
40
id="now-playing"
···
38
49
--small-box-mask-png: url("${smallBoxMask.src}");
39
50
`}
40
51
>
41
41
-
<div
42
42
-
class="player"
43
43
-
tabindex="0"
44
44
-
style={`display: ${track instanceof SpotifyError ? "none" : "block"};` +
45
45
-
new Array(5)
46
46
-
.fill(0)
47
47
-
.map(
48
48
-
(_, i) =>
49
49
-
`--head-move-${(i + 2) * 10}: ${Math.random() * 20 + 25}deg;`,
50
50
-
)
51
51
-
.join("")}
52
52
-
>
52
52
+
<div class="player" tabindex="0">
53
53
<div class="spinner"></div>
54
54
55
55
<div class="record">
···
59
59
: track.album.images[0].url}
60
60
alt=""
61
61
class="art"
62
62
-
style={`display: ${track instanceof SpotifyError ? "none" : "block"}`}
63
62
/>
64
63
</div>
65
64
···
67
66
<div class="head"></div>
68
67
</div>
69
68
70
70
-
<now-playing>
69
69
+
<now-playing data-render={dataTrack(track)}>
71
70
<a
72
71
slot="title"
73
73
-
href={(dataTrack(track) && track.external_urls.spotify) || ""}
72
72
+
href={dataTrack(track) ? track.external_urls.spotify : "#"}
74
73
>
75
75
-
{dataTrack(track) && track.name}</a
76
76
-
>
77
77
-
<span slot="album">{dataTrack(track) && track.album.name}</span>
74
74
+
{dataTrack(track) ? track.name : null}
75
75
+
</a>
76
76
+
<span slot="album">{dataTrack(track) ? track.album.name : null}</span>
78
77
<span slot="artists">
79
78
{
80
80
-
dataTrack(track) &&
81
81
-
track.artists
82
82
-
.map((artist) => (
83
83
-
<a href={artist.external_urls.spotify}>{artist.name}</a>
84
84
-
))
85
85
-
// inject a comma before each entry in the list except the first one
86
86
-
// flatmap flattens the returned array into the new map
87
87
-
.flatMap((x, i) => (i === 0 ? x : [", ", x]))
79
79
+
dataTrack(track)
80
80
+
? track.artists
81
81
+
.map((artist) => (
82
82
+
<a href={artist.external_urls.spotify}>{artist.name}</a>
83
83
+
))
84
84
+
// inject a comma before each entry in the list except the first one
85
85
+
// flatmap flattens the returned array into the new map
86
86
+
.flatMap((x, i) => (i === 0 ? x : [", ", x]))
87
87
+
: null
88
88
}
89
89
</span>
90
90
<img
···
110
110
</div>
111
111
112
112
<style>
113
113
+
/* dont show element if it errored or nothing is playing */
114
114
+
:host([data-render="false"]) {
115
115
+
display: none !important;
116
116
+
}
117
117
+
113
118
:host {
114
119
contain: layout;
115
120
position: absolute;
···
173
178
</now-playing>
174
179
</div>
175
180
</section>
176
176
-
177
177
-
{
178
178
-
track instanceof SpotifyError && (
179
179
-
<script
180
180
-
set:html={`console.error("Failed to load nowPlaying:", ${JSON.stringify(track)})`}
181
181
-
/>
182
182
-
)
183
183
-
}
184
181
185
182
<style>
186
183
@keyframes spin {