From fffe549dbc228abe7f288d85390ad0dc93543e69 Mon Sep 17 00:00:00 2001 From: pedromcunha Date: Tue, 5 Nov 2024 13:59:39 -0500 Subject: [PATCH 1/3] Handle unhandled http errors in usePrice --- packages/hooks/src/hooks/usePrice.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/hooks/src/hooks/usePrice.ts b/packages/hooks/src/hooks/usePrice.ts index 6d21abe6..2d3b2e6d 100644 --- a/packages/hooks/src/hooks/usePrice.ts +++ b/packages/hooks/src/hooks/usePrice.ts @@ -59,14 +59,20 @@ export default function usePrice( const response = (useQuery as QueryType)({ queryKey: ['usePrice', options], queryFn: () => { - if (options && client?.source && !options.referrer) { - options.referrer = client.source - } - const promise = queryPrice(client?.baseApiUrl, options) - promise.then((response: any) => { - onResponse?.(response) + return new Promise((res, rej) => { + if (options && client?.source && !options.referrer) { + options.referrer = client.source + } + const promise = queryPrice(client?.baseApiUrl, options) + promise + .then((response: any) => { + res(response) + onResponse?.(response) + }) + .catch((e) => { + rej(e) + }) }) - return promise }, enabled: client !== undefined && options !== undefined, retry: false, From e3bb255cfbe6c14c2b23df7f7ff1329e7358a7d6 Mon Sep 17 00:00:00 2001 From: pedromcunha Date: Tue, 5 Nov 2024 14:00:47 -0500 Subject: [PATCH 2/3] Rename promise methods --- packages/hooks/src/hooks/usePrice.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/hooks/src/hooks/usePrice.ts b/packages/hooks/src/hooks/usePrice.ts index 2d3b2e6d..82945ca5 100644 --- a/packages/hooks/src/hooks/usePrice.ts +++ b/packages/hooks/src/hooks/usePrice.ts @@ -59,18 +59,18 @@ export default function usePrice( const response = (useQuery as QueryType)({ queryKey: ['usePrice', options], queryFn: () => { - return new Promise((res, rej) => { + return new Promise((resolve, reject) => { if (options && client?.source && !options.referrer) { options.referrer = client.source } const promise = queryPrice(client?.baseApiUrl, options) promise .then((response: any) => { - res(response) + resolve(response) onResponse?.(response) }) .catch((e) => { - rej(e) + reject(e) }) }) }, From 1c68705b4ea034f6bf8f33ba19ba0ffa6bfd244c Mon Sep 17 00:00:00 2001 From: pedromcunha Date: Tue, 5 Nov 2024 14:01:14 -0500 Subject: [PATCH 3/3] feat: changeset --- .changeset/sixty-adults-provide.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/sixty-adults-provide.md diff --git a/.changeset/sixty-adults-provide.md b/.changeset/sixty-adults-provide.md new file mode 100644 index 00000000..60b242ab --- /dev/null +++ b/.changeset/sixty-adults-provide.md @@ -0,0 +1,5 @@ +--- +'@reservoir0x/relay-kit-hooks': patch +--- + +Fix usePrice error handling