strapi-sdk-javascript icon indicating copy to clipboard operation
strapi-sdk-javascript copied to clipboard

Properly stringify error

Open MartinMuzatko opened this issue 4 years ago • 4 comments

Related to #47

Informations

  • Node.js version: 12.14.0
  • npm version: 6.13.4
  • Strapi version: beta-19
  • Strapi-sdk-javascript version: 0.3.3
  • Browser or Node.js: NodeJS

What is the current behavior?

Right now, I can only retrieve [Object, object] as error message, because Errors in JavaScript are stringified before stored in the Error object. https://github.com/strapi/strapi-sdk-javascript/blob/master/src/lib/sdk.ts#L99

Steps to reproduce the problem

e.g. register without passing email, anything that is producing a non 2xx/3xx status code

What is the expected behavior?

I should be able to retrieve the complete response and response body. Alternatively every known error should be its own Error class, since multiple things can go wrong, this is not always feasible (e.g. username and email missing errors)

Suggested solutions

I propose these solutions. Pick one or multiple.

  • Add .toString method to the received response to e.g. instead do JSON.stringify
  • Attach custom data to the error. e.g. error.response

Confirm

  • [X] I'm somewhat sure that this issue hasn't already been referenced

MartinMuzatko avatar Mar 25 '20 14:03 MartinMuzatko