From ce1619a3f5d4a3febcc3448ce1940bf14deddc1c Mon Sep 17 00:00:00 2001 From: Kevin He Date: Wed, 9 Oct 2024 16:58:23 -0700 Subject: [PATCH 1/3] Update README.md --- README.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d6c035bc..cfa17696 100644 --- a/README.md +++ b/README.md @@ -84,10 +84,35 @@ const config = { For more info, refer to the [documentation site](https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/). +#### `throwOnBasResponse` + +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 From 037a9da47a7cf56985dd932f1dbca457110fb4e0 Mon Sep 17 00:00:00 2001 From: Kevin He Date: Wed, 9 Oct 2024 16:59:35 -0700 Subject: [PATCH 2/3] Update README.md --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index cfa17696..4d02e695 100644 --- a/README.md +++ b/README.md @@ -100,14 +100,14 @@ const shopperSearch = new ShopperSearch({ // 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: ",,,"} - } + 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 From aecb04eeb58733b35310a1ddcdc0f86415f884ba Mon Sep 17 00:00:00 2001 From: Kevin He Date: Wed, 9 Oct 2024 17:16:18 -0700 Subject: [PATCH 3/3] Update README.md Co-authored-by: Alex Vuong --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4d02e695..8bb2767b 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ const config = { For more info, refer to the [documentation site](https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/). -#### `throwOnBasResponse` +#### `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()`.