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.
Context
There are certain errors that Shippo will return that result in a
JSON parse
error. When this happens, it will return a genericShippoAPIError
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