Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/yummy-toys-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Better error messages for failed requests
6 changes: 4 additions & 2 deletions apps/wallet-ui/src/lib/assets/erc721.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ export async function getErc721Tokens({
);

if (!response.ok) {
response.body?.cancel();
console.error("Failed to fetch NFTs");
const error = await response.text().catch(() => null);
console.error(
`Failed to fetch NFTs: ${response.status} - ${response.statusText}: ${error || "unknown error"}`,
);
return {
nextCursor: undefined,
tokens: [],
Expand Down
6 changes: 4 additions & 2 deletions apps/wallet-ui/src/lib/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ export async function getChains() {
);

if (!response.ok) {
response.body?.cancel();
throw new Error("Failed to fetch chains");
const error = await response.text().catch(() => null);
throw new Error(
`Failed to fetch chains: ${response.status} - ${response.statusText}: ${error || "unknown error"}`,
);
}

return (await response.json()).data as ChainMetadata[];
Expand Down
6 changes: 4 additions & 2 deletions packages/thirdweb/src/pay/buyWithCrypto/getHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ export async function getBuyWithCryptoHistory(

// Assuming the response directly matches the SwapResponse interface
if (!response.ok) {
response.body?.cancel();
throw new Error(`HTTP error! status: ${response.status}`);
const error = await response.text().catch(() => null);
throw new Error(
`HTTP error! status: ${response.status} - ${response.statusText}: ${error || "unknown error"}`,
);
}

const data: BuyWithCryptoHistoryData = (await response.json()).result;
Expand Down
6 changes: 4 additions & 2 deletions packages/thirdweb/src/pay/buyWithCrypto/getStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ export async function getBuyWithCryptoStatus(

// Assuming the response directly matches the BuyWithCryptoStatus interface
if (!response.ok) {
response.body?.cancel();
throw new Error(`HTTP error! status: ${response.status}`);
const error = await response.text().catch(() => null);
throw new Error(
`HTTP error! status: ${response.status} - ${response.statusText}: ${error || "unknown error"}`,
);
}

const data: BuyWithCryptoStatus = (await response.json()).result;
Expand Down
6 changes: 4 additions & 2 deletions packages/thirdweb/src/pay/buyWithFiat/getHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ export async function getBuyWithFiatHistory(

// Assuming the response directly matches the BuyWithFiatStatus response interface
if (!response.ok) {
response.body?.cancel();
throw new Error(`HTTP error! status: ${response.status}`);
const error = await response.text().catch(() => null);
throw new Error(
`HTTP error! status: ${response.status} - ${response.statusText}: ${error || "unknown error"}`,
);
}

const data: BuyWithFiatHistoryData = (await response.json()).result;
Expand Down
6 changes: 4 additions & 2 deletions packages/thirdweb/src/pay/buyWithFiat/getStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,10 @@ export async function getBuyWithFiatStatus(
const response = await getClientFetch(params.client)(url);

if (!response.ok) {
response.body?.cancel();
throw new Error(`HTTP error! status: ${response.status}`);
const error = await response.text().catch(() => null);
throw new Error(
`HTTP error! status: ${response.status} - ${response.statusText}: ${error || "unknown error"}`,
);
}

return (await response.json()).result;
Expand Down
6 changes: 4 additions & 2 deletions packages/thirdweb/src/pay/getBuyHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ export async function getBuyHistory(

// Assuming the response directly matches the SwapResponse interface
if (!response.ok) {
response.body?.cancel();
throw new Error(`HTTP error! status: ${response.status}`);
const error = await response.text().catch(() => null);
throw new Error(
`HTTP error! status: ${response.status} - ${response.statusText}: ${error || "unknown error"}`,
);
}

const data: BuyHistoryData = (await response.json()).result;
Expand Down
10 changes: 6 additions & 4 deletions packages/thirdweb/src/rpc/fetch-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ export async function fetchRpc(
});

if (!response.ok) {
response.body?.cancel();
const error = await response.text().catch(() => null);
throw new Error(
`RPC request failed with status ${response.status} - ${response.statusText}`,
`RPC request failed with status ${response.status} - ${response.statusText}: ${error || "unknown error"}`,
);
}

Expand Down Expand Up @@ -116,8 +116,10 @@ export async function fetchSingleRpc(
});

if (!response.ok) {
response.body?.cancel();
throw new Error(`RPC request failed with status ${response.status}`);
const error = await response.text().catch(() => null);
throw new Error(
`RPC request failed with status ${response.status} - ${response.statusText}: ${error || "unknown error"}`,
);
}
if (response.headers.get("Content-Type")?.startsWith("application/json")) {
return await response.json();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ export async function relayBiconomyTransaction(
},
);
if (!response.ok) {
response.body?.cancel();
throw new Error(`Failed to send transaction: ${await response.text()}`);
}
const json = await response.json();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ export async function relayOpenZeppelinTransaction(
});

if (!response.ok) {
response.body?.cancel();
throw new Error(`Failed to send transaction: ${await response.text()}`);
}
const json = await response.json();
Expand Down
Loading