-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle validation error from commerce-sdk-isomorphic (#718)
* 1st attempt at disabling retry when seeing validation error * Make sure the retries would stop * Add todos * Add comment * Some refactoring and typing * Remove some guards * Add comments * Remove comments * Demonstrate user error * React Query's retries are now done only for 5xx server errors * For easier debugging * Revert change Since we plan to remove the QueryClientProvider in our commerce hooks. See PR #734 * Disable retries And set the option at the individual query level. * Revert adding query options on individual queries * Remove todo We can't use ResponseError yet, since it's not exported by the isomorphic sdk. * Create a new page to see the errors * Test validation error
- Loading branch information
Showing
6 changed files
with
110 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/test-commerce-sdk-react/app/pages/query-errors.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (c) 2022, Salesforce, Inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import React from 'react' | ||
import {useProducts, useProduct} from 'commerce-sdk-react' | ||
import Json from '../components/Json' | ||
|
||
const QueryErrors = () => { | ||
// @ts-ignore | ||
const products = useProducts({FOO: ''}) | ||
const product = useProduct({id: '25502228Mxxx'}) | ||
|
||
return ( | ||
<> | ||
<h1>Query Errors</h1> | ||
|
||
<p> | ||
Two common errors you'll find when using the{' '} | ||
<code>commerce-sdk-isomorphic</code> library are: | ||
</p> | ||
<ul> | ||
<li> | ||
<strong>Validation error</strong> (e.g. when you pass in the wrong arguments to | ||
the function call) | ||
</li> | ||
<li> | ||
<strong>Response error</strong> (e.g. 4xx and 5xx http errors from the | ||
underlying Commerce API) | ||
</li> | ||
</ul> | ||
|
||
<h2>Validation Error</h2> | ||
{products.isLoading && <p style={{background: 'aqua'}}>Loading...</p>} | ||
{products.error && <p style={{color: 'red'}}>Something is wrong</p>} | ||
|
||
<div> | ||
<div>Returning data</div> | ||
<Json | ||
data={{ | ||
isLoading: products.isLoading, | ||
error: products.error, | ||
data: products.data | ||
}} | ||
/> | ||
</div> | ||
|
||
<h2>Response Error</h2> | ||
{product.isLoading && <p style={{background: 'aqua'}}>Loading...</p>} | ||
{product.error && <p style={{color: 'red'}}>Something is wrong</p>} | ||
|
||
<div> | ||
<div>Returning data</div> | ||
<Json | ||
data={{ | ||
isLoading: product.isLoading, | ||
error: product.error, | ||
data: product.data | ||
}} | ||
/> | ||
</div> | ||
</> | ||
) | ||
} | ||
|
||
QueryErrors.getTemplateName = () => 'QueryErrors' | ||
|
||
export default QueryErrors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters