spotify-api.js
spotify-api.js copied to clipboard
Uncaught promise rejection causing program to crash
Bug Report
Since https://github.com/spotify-api/spotify-api.js/blob/967f9490ea4c8b482f71f2de481bd5033ab2fd70/src/Client.ts#L130 is not awaited or called with .catch(...)
after it, Node will exit if the promise returned by this._init()
rejects.
It's a bit tricky because it is called in the constructor which means we can't just add await
in front of it and I don't know enough about the codebase to suggest how to refactor it at the moment.
What i expected:
A failed API request should not make the process exit.
What actually happened:
A bad response when trying to refresh the token causes the process to exit
/Users/richardmiller/srv/ricky-js-monorepo/node_modules/axios/lib/core/settle.js:19
reject(new AxiosError(
^
AxiosError: Request failed with status code 503
at settle (/Users/richardmiller/srv/ricky-js-monorepo/node_modules/axios/lib/core/settle.js:19:12)
at Unzip.handleStreamEnd (/Users/richardmiller/srv/ricky-js-monorepo/node_modules/axios/lib/adapters/http.js:548:11)
at Unzip.emit (node:events:538:35)
at Unzip.emit (node:domain:475:12)
at endReadableNT (node:internal/streams/readable:1345:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'ERR_BAD_RESPONSE',
(... removed unrelated stuff ...)
url: 'https://accounts.spotify.com/api/token',
params: {
grant_type: 'refresh_token',
code: undefined,
(... removed unrelated stuff ...)
To reproduce this bug:
Difficult to reproduce because it is caused by 503 from Spotify.
-
Node Version:
-
Library Version:
-
[x] I have already checked issues regarding this bug.
-
[ ] This problem is generated due to version migration.
You don't have to worry about the promise rejection in _init
function there as the _init
function involves a try catch statement. If there are any errors thrown, it is the SpotifyAPIError or the AxiosError. The package uses endpoints, resources for few endpoints are outdated as the spotify api has changed its few structures.
As i am the only one maintaining the module, it will take some time to fix this (probably more than a month). It would be better if you send the code which led to the error.