appbaseio / appbase-js

appbase.io search client library for JavaScript
MIT License
42 stars 18 forks source link

Improve promise rejection response #46

Closed divyanshu013 closed 2 years ago

divyanshu013 commented 5 years ago

Currently in case of error status >= 400, the promise is rejected with a response object that was already transformed code. It should instead pass the transformed object (data) in this case.

For example, here's the actual error message for a request that went wrong:

{"status":403,"message":"User doesn't have write permission."}

And here is the error that was caught:

{ type: "default", status: 403, ok: false, statusText: "Forbidden", headers: {…}, url: "https://scalr.api.appbase.io/MovieAppFinal/MovieAppFinal/AWNAO8-Q5Q83Zq9GcV4q/_update?", _bodyInit: Blob, _bodyBlob: Blob, bodyUsed: true }

This makes error handling tricky.

Steps to replicate

  1. Make a write request with read only credentials
  2. Catch the error and log it
  3. The caught error and reponse from server should match