I'm pretty sure this is caused by the JSON being empty but I'm trying to get the current song I'm playing on Spotify using node-fetch, any attempt at even calling response.json()
causes the application to exit with this error:
SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at Response.json (file:///C:/Users/44778/downloads/test/node_modules/node-fetch/src/body.js:149:15)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Here is my code:
fetch('https://api.spotify.com/v1/me/player/currently-playing', {
method: 'GET', headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + accessToken
}
}).then((response) => {
try {
console.log(response.json().then(
(data) => { console.log(data) }
).catch((e) => { console.log(e)}));
} catch (error) {
console.log(error);
}
});