Skip to content

Commit 62ce05e

Browse files
[SDK] Improve error message for getUser (#6758)
1 parent 563c4c7 commit 62ce05e

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

.changeset/twenty-cows-take.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+
Better error message for getUser

packages/thirdweb/src/wallets/in-app/core/users/getUser.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,17 @@ describe("getUser", () => {
190190
it("should handle fetch errors", async () => {
191191
mockFetch.mockResolvedValueOnce({
192192
ok: false,
193+
status: 404,
194+
statusText: "Not Found",
195+
text: async () => "some message",
193196
});
194197

195198
await expect(
196199
getUser({
197200
client: mockClient,
198201
walletAddress: "0x123",
199202
}),
200-
).rejects.toThrow("Failed to get profiles");
203+
).rejects.toThrow("Failed to get profiles. 404 Not Found: some message");
201204
});
202205

203206
it("should return null if no user is found", async () => {

packages/thirdweb/src/wallets/in-app/core/users/getUser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ export async function getUser({
9595
const res = await clientFetch(url.toString());
9696

9797
if (!res.ok) {
98-
throw new Error("Failed to get profiles");
98+
const error = await res.text().catch(() => "Unknown error");
99+
throw new Error(
100+
`Failed to get profiles. ${res.status} ${res.statusText}: ${error}`,
101+
);
99102
}
100103

101104
const data = (await res.json()) as {

0 commit comments

Comments
 (0)