Skip to content

Commit

Permalink
add docs for error handling (#174)
Browse files Browse the repository at this point in the history
* Update README.md

* Update README.md

* Update README.md

Co-authored-by: Alex Vuong <[email protected]>

---------

Co-authored-by: Alex Vuong <[email protected]>
  • Loading branch information
kevinxh and alexvuong authored Oct 10, 2024
1 parent b4161fa commit c9c116f
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,35 @@ const config = {

For more info, refer to the [documentation site](https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/).

#### `throwOnBadResponse`

When `true`, the SDK throws an `Error` on responses whose status is not 2xx or 304. By default, the value of this flag is `false` for backwards compatibility. Below is an example for accessing the error object via `e.response.json()`.

```js
const config = {
throwOnBadResponse: true
// rest of the config object...
};

const shopperSearch = new ShopperSearch({
...config
});

// in an async function
try {
const searchResult = await shopperSearch.productSearch({
parameters: { q: "shirt" },
});
} catch (e) {
const error = await e.response.json();
console.log(error);
// error is the JSON object - {error: ",,,"}
}
```

#### Additional Config Settings

* `headers`: Headers to include with API requests.
* `throwOnBadResponse`: When `true`, the SDK throws an `Error` on responses whose status is not 2xx or 304.

### Custom Query Parameters

Expand Down

0 comments on commit c9c116f

Please sign in to comment.