spotify-web-api-ts icon indicating copy to clipboard operation
spotify-web-api-ts copied to clipboard

feat(spotifyaxios.ts): add spotify error message to axios error

Open thomas-negrault opened this issue 3 years ago • 2 comments

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)

thomas-negrault avatar Dec 22 '21 11:12 thomas-negrault

@adamgrieger are you open to merging and releasing this? (Also, are you looking for collaborators on this project?)

schickling avatar Mar 22 '22 08:03 schickling

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

finnmerlett avatar Apr 26 '22 10:04 finnmerlett