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/orange-icons-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Simplify RPC request handling
22 changes: 2 additions & 20 deletions packages/thirdweb/src/rpc/fetch-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,7 @@
);
}

if (response.headers.get("Content-Type")?.startsWith("application/json")) {
return await response.json();
}
const text = await response.text();
try {
return JSON.parse(text);
} catch (err) {
console.error("Error parsing response", err, text);
throw err;
}
return await response.json();
}

type FetchSingleRpcOptions = {
Expand Down Expand Up @@ -121,14 +112,5 @@
`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();
}
const text = await response.text();
try {
return JSON.parse(text);
} catch (err) {
console.error("Error parsing response", err, text);
throw err;
}
return await response.json();

Check warning on line 115 in packages/thirdweb/src/rpc/fetch-rpc.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L115 was not covered by tests
}
6 changes: 5 additions & 1 deletion packages/thirdweb/src/rpc/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@

// No response.
if (!response) {
inflight.reject(new Error("No response"));
inflight.reject(
new Error(
`No response for index ${index} - all responses: ${stringify(responses)}`,
),
);

Check warning on line 151 in packages/thirdweb/src/rpc/rpc.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/rpc/rpc.ts#L147-L151

Added lines #L147 - L151 were not covered by tests
}
// Response is an error or error string.
else if (response instanceof Error) {
Expand Down
Loading