mirror of
https://github.com/skidoodle/albert.lol.git
synced 2025-02-15 06:09:15 +01:00
init spotify fix
This commit is contained in:
parent
c634d9225a
commit
2856debcd9
2 changed files with 7 additions and 6 deletions
|
@ -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.',
|
||||
})
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue