init spotify fix

This commit is contained in:
skidoodle 2024-01-22 09:27:26 +01:00
parent c634d9225a
commit 2856debcd9
2 changed files with 7 additions and 6 deletions

View file

@ -21,11 +21,13 @@ export default async function handler(
) { ) {
try { try {
const song = await spotify.getCurrentSong() const song = await spotify.getCurrentSong()
if (!song || !song.is_playing) { if (!song || !song.is_playing) {
return res.status(200).json({ return res.status(200).json({
is_playing: false, is_playing: false,
}) })
} }
res.status(200).json({ res.status(200).json({
is_playing: true, is_playing: true,
album: { album: {
@ -43,8 +45,8 @@ export default async function handler(
duration: song.duration, duration: song.duration,
}) })
} catch (error) { } catch (error) {
res res.status(500).json({
.status(500) error: 'An error occurred while fetching the song.',
.json({ error: 'An error occurred while fetching the song.' }) })
} }
} }

View file

@ -42,7 +42,7 @@ export class SpotifyService {
} }
} }
public async getCurrentSong(): Promise<SongResult> { public async getCurrentSong(): Promise<SongResult | undefined> {
try { try {
if (!this.hasAccessToken()) { if (!this.hasAccessToken()) {
await this.getAccessToken() await this.getAccessToken()
@ -61,9 +61,8 @@ export class SpotifyService {
}) })
return SongResultMap.parseSong(response.data) return SongResultMap.parseSong(response.data)
} catch (error) { } catch {
await this.getAccessToken() await this.getAccessToken()
throw error
} }
} }
} }