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 {
const song = await spotify.getCurrentSong()
if (!song || !song.is_playing) {
return res.status(200).json({
is_playing: false,
})
}
res.status(200).json({
is_playing: true,
album: {
@ -43,8 +45,8 @@ export default async function handler(
duration: song.duration,
})
} catch (error) {
res
.status(500)
.json({ error: 'An error occurred while fetching the song.' })
res.status(500).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 {
if (!this.hasAccessToken()) {
await this.getAccessToken()
@ -61,9 +61,8 @@ export class SpotifyService {
})
return SongResultMap.parseSong(response.data)
} catch (error) {
} catch {
await this.getAccessToken()
throw error
}
}
}