diff --git a/.changeset/twenty-cows-take.md b/.changeset/twenty-cows-take.md new file mode 100644 index 00000000000..d913c800805 --- /dev/null +++ b/.changeset/twenty-cows-take.md @@ -0,0 +1,5 @@ +--- +"thirdweb": patch +--- + +Better error message for getUser diff --git a/packages/thirdweb/src/wallets/in-app/core/users/getUser.test.ts b/packages/thirdweb/src/wallets/in-app/core/users/getUser.test.ts index fe58598acb4..725528744c9 100644 --- a/packages/thirdweb/src/wallets/in-app/core/users/getUser.test.ts +++ b/packages/thirdweb/src/wallets/in-app/core/users/getUser.test.ts @@ -190,6 +190,9 @@ describe("getUser", () => { it("should handle fetch errors", async () => { mockFetch.mockResolvedValueOnce({ ok: false, + status: 404, + statusText: "Not Found", + text: async () => "some message", }); await expect( @@ -197,7 +200,7 @@ describe("getUser", () => { client: mockClient, walletAddress: "0x123", }), - ).rejects.toThrow("Failed to get profiles"); + ).rejects.toThrow("Failed to get profiles. 404 Not Found: some message"); }); it("should return null if no user is found", async () => { diff --git a/packages/thirdweb/src/wallets/in-app/core/users/getUser.ts b/packages/thirdweb/src/wallets/in-app/core/users/getUser.ts index 26d02b923df..203456a8e03 100644 --- a/packages/thirdweb/src/wallets/in-app/core/users/getUser.ts +++ b/packages/thirdweb/src/wallets/in-app/core/users/getUser.ts @@ -95,7 +95,10 @@ export async function getUser({ const res = await clientFetch(url.toString()); if (!res.ok) { - throw new Error("Failed to get profiles"); + const error = await res.text().catch(() => "Unknown error"); + throw new Error( + `Failed to get profiles. ${res.status} ${res.statusText}: ${error}`, + ); } const data = (await res.json()) as {