Skip to content

Commit c475fd0

Browse files
[thirdweb] Simplify RPC request handling
1 parent 1825ac8 commit c475fd0

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

.changeset/orange-icons-hide.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+
Simplify RPC request handling

packages/thirdweb/src/rpc/fetch-rpc.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,7 @@ export async function fetchRpc(
7878
);
7979
}
8080

81-
if (response.headers.get("Content-Type")?.startsWith("application/json")) {
82-
return await response.json();
83-
}
84-
const text = await response.text();
85-
try {
86-
return JSON.parse(text);
87-
} catch (err) {
88-
console.error("Error parsing response", err, text);
89-
throw err;
90-
}
81+
return await response.json();
9182
}
9283

9384
type FetchSingleRpcOptions = {
@@ -121,14 +112,5 @@ export async function fetchSingleRpc(
121112
`RPC request failed with status ${response.status} - ${response.statusText}: ${error || "unknown error"}`,
122113
);
123114
}
124-
if (response.headers.get("Content-Type")?.startsWith("application/json")) {
125-
return await response.json();
126-
}
127-
const text = await response.text();
128-
try {
129-
return JSON.parse(text);
130-
} catch (err) {
131-
console.error("Error parsing response", err, text);
132-
throw err;
133-
}
115+
return await response.json();
134116
}

packages/thirdweb/src/rpc/rpc.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ export function getRpcClient(
144144

145145
// No response.
146146
if (!response) {
147+
console.error(
148+
`No response for index ${index} - all responses: ${stringify(responses)}`,
149+
);
147150
inflight.reject(new Error("No response"));
148151
}
149152
// Response is an error or error string.

0 commit comments

Comments
 (0)