goshippo / shippo-node-client

Shipping API Node.js library (USPS, FedEx, UPS and more)
https://goshippo.com/docs
MIT License
136 stars 54 forks source link

(feature) Enable more visibility into all response errors #74

Closed solomonjames closed 2 years ago

solomonjames commented 2 years ago

Context

There are certain errors that Shippo will return that result in a JSON parse error. When this happens, it will return a generic ShippoAPIError without any response data to help understand what actually happened.

This is most evident when hitting the Shippo API rate limit, which will trigger a 429. In this case, the node-client will throw the generic error, without that status code or anything to truly know that is what happened.

Analysis

The error already supports adding in additional context, such as status code, we simply need to adjust the data passed into the error.

Solution

Moving the default errData variable up, and using that in the same manner as the other errors with the generic JSON parse error.

Testing

New tests were added to check for this new expectation.

npm run test