Skip to content

Commit 2dba042

Browse files
[SDK] Improve destination tokens error handling (#6910)
1 parent c271ec6 commit 2dba042

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

.changeset/flat-bears-try.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Improve destination tokens error handling

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
getPaySupportedSources,
88
} from "../../../../../../../pay/utils/definitions.js";
99
import { getClientFetch } from "../../../../../../../utils/fetch.js";
10+
import { stringify } from "../../../../../../../utils/json.js";
1011
import { withCache } from "../../../../../../../utils/promise/withCache.js";
1112

1213
type Response = {
@@ -44,7 +45,16 @@ export async function fetchBuySupportedDestinations(
4445
const res = await fetchWithHeaders(
4546
`${getPaySupportedDestinations()}${isTestMode ? "?isTestMode=true" : ""}`,
4647
);
48+
if (!res.ok) {
49+
const error = await res.text();
50+
throw new Error(`Failed to fetch supported destinations: ${error}`);
51+
}
4752
const data = (await res.json()) as Response;
53+
if (!data.result) {
54+
throw new Error(
55+
`Failed to parse supported destinations: ${data ? stringify(data) : undefined}`,
56+
);
57+
}
4858
return data.result.map((item) => ({
4959
chain: defineChain({
5060
id: item.chainId,

0 commit comments

Comments
 (0)