From eb0c06c303eef47d7591dfa88deb945e521d4415 Mon Sep 17 00:00:00 2001
From: Vincent Marta
Date: Mon, 3 Oct 2022 17:23:36 -0700
Subject: [PATCH] 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
---
.../src/hooks/ShopperProducts/query.test.tsx | 22 ++++++
.../src/hooks/ShopperProducts/query.ts | 9 ---
.../commerce-sdk-react/src/test-utils.tsx | 5 +-
.../app/pages/home.tsx | 8 +++
.../app/pages/query-errors.tsx | 71 +++++++++++++++++++
.../test-commerce-sdk-react/app/routes.tsx | 5 ++
6 files changed, 110 insertions(+), 10 deletions(-)
create mode 100644 packages/test-commerce-sdk-react/app/pages/query-errors.tsx
diff --git a/packages/commerce-sdk-react/src/hooks/ShopperProducts/query.test.tsx b/packages/commerce-sdk-react/src/hooks/ShopperProducts/query.test.tsx
index 5f1f795fb2..eb419be4ff 100644
--- a/packages/commerce-sdk-react/src/hooks/ShopperProducts/query.test.tsx
+++ b/packages/commerce-sdk-react/src/hooks/ShopperProducts/query.test.tsx
@@ -83,6 +83,19 @@ const CategoryComponent = ({id}: {id: string}): ReactElement => {
)
}
+
+const IncorrectArguments = (): ReactElement => {
+ // @ts-ignore
+ const {isLoading, error} = useProducts({FOO: ''})
+
+ return (
+