Skip to content

Commit 23d3757

Browse files
[SDK] Simplify RPC request handling (#6752)
1 parent e7b0110 commit 23d3757

File tree

3 files changed

+12
-21
lines changed

3 files changed

+12
-21
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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ export function getRpcClient(
144144

145145
// No response.
146146
if (!response) {
147-
inflight.reject(new Error("No response"));
147+
inflight.reject(
148+
new Error(
149+
`No response for index ${index} - all responses: ${stringify(responses)}`,
150+
),
151+
);
148152
}
149153
// Response is an error or error string.
150154
else if (response instanceof Error) {

0 commit comments

Comments
 (0)