We recently added the useCustomQuery hook to the commerce-sdk-react library. But we forgot to ensure that we are passing the throwOnBadResponse=true argument. This meant that custom apis that were returning error status codes weren't throwing errors resulting in the hooks query status being a "success" when it should be an "error". This PR fixes this by passing this argument in.
Types of Changes
[x] Bug fix (non-breaking change that fixes an issue)
[ ] New feature (non-breaking change that adds functionality)
[ ] Documentation update
[ ] Breaking change (could cause existing functionality to not work as expected)
[ ] Other changes (non-breaking changes that does not fit any of the above)
Changes
Pass throwOnBadResponse=true to isomorphic helper in useCustomQuery
Add tests
Update test commerce sdk react project to visualize errors
Bump verion
Add change log
How to Test-Drive This PR
Run the test-commerce-sdk-react project and goto http://localhost:3000/custom-endpoint
You should see a some successful response data.
Now change line 19 of the pages/use-custom-endpoint.tsx to be apiName: 'hello-world-bad'
The page should refresh showing "something is wrong" implying an error was thrown and the "error" object was defined for the query return value.
Checklists
General
[x] Changes are covered by test cases
[x] CHANGELOG.md updated with a short description of changes (not required for documentation updates)
Description
We recently added the
useCustomQuery
hook to thecommerce-sdk-react
library. But we forgot to ensure that we are passing thethrowOnBadResponse=true
argument. This meant that custom apis that were returning error status codes weren't throwing errors resulting in the hooks query status being a "success" when it should be an "error". This PR fixes this by passing this argument in.Types of Changes
Changes
throwOnBadResponse=true
to isomorphic helper inuseCustomQuery
How to Test-Drive This PR
test-commerce-sdk-react
project and gotohttp://localhost:3000/custom-endpoint
pages/use-custom-endpoint.tsx
to beapiName: 'hello-world-bad'
Checklists
General