spotify-web-api-ts
spotify-web-api-ts copied to clipboard
feat(spotifyaxios.ts): add spotify error message to axios error
When working with this library, I got a 400 bad request and it took me a while to troubleshoot the issue. This could save some time by including the error message returned by the spotify api. In my case the spotify api was returning:
error: {
status: 400,
message: 'You can add a maximum of 100 tracks per request.'
}
Without this change, all I got in the console was:
Error: Request failed with status code 400
at Object.<anonymous> ({project}/node_modules/spotify-web-api-ts/src/helpers/spotifyAxios.ts:30:11)
at Generator.throw (<anonymous>)
at rejected ({project}node_modules/spotify-web-api-ts/cjs/helpers/spotifyAxios.js:6:65)
And now:
Error: Request failed with status code 400: You can add a maximum of 100 tracks per request.
at Object.<anonymous> ({project}node_modules/spotify-web-api-ts/src/helpers/spotifyAxios.ts:30:11)
at Generator.throw (<anonymous>)
at rejected ({project}/node_modules/spotify-web-api-ts/cjs/helpers/spotifyAxios.js:6:65)
@adamgrieger are you open to merging and releasing this? (Also, are you looking for collaborators on this project?)
In addition to this it would be great to have the details of the spotify response available on the error object. To that end, I can't understand why this package owner rethrows the axios error message returned as a new error, discarding all that useful axios info. Why wouldn't they just let the axios error thrown propagate? https://github.com/adamgrieger/spotify-web-api-ts/blob/d7e290e2e8c57a4c6e8b637d6c79d468992c46af/src/helpers/spotifyAxios.ts#L28-L31