Skip to content

[SDK] Propagate 401 errors when connecting in-app wallet #7040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

joaquim-verges
Copy link
Member

@joaquim-verges joaquim-verges commented May 13, 2025


PR-Codex overview

This PR focuses on improving error handling in the getUserStatus function within the get-enclave-user-status.ts file. It changes the way 401 errors are handled and modifies the return type of the function.

Detailed summary

  • Changed the return type of getUserStatus from Promise<UserStatus | undefined> to Promise<UserStatus>.
  • Removed the handling of 401 errors that returned undefined when no user was logged in.
  • Updated error handling to return a more descriptive error message using response.text() instead of response.json().

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Copy link

vercel bot commented May 13, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 14, 2025 1:46am
login ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 14, 2025 1:46am
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 14, 2025 1:46am
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 14, 2025 1:46am
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 14, 2025 1:46am

Copy link

changeset-bot bot commented May 13, 2025

🦋 Changeset detected

Latest commit: 1318c75

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
thirdweb Patch
@thirdweb-dev/wagmi-adapter Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions bot added packages SDK Involves changes to the thirdweb SDK labels May 13, 2025
@joaquim-verges joaquim-verges changed the title Propagate 401 errors when connecting in-app wallet [SDK] Propagate 401 errors when connecting in-app wallet May 13, 2025
@joaquim-verges joaquim-verges marked this pull request as ready for review May 13, 2025 23:49
@joaquim-verges joaquim-verges requested review from a team as code owners May 13, 2025 23:49
Comment on lines 35 to 41
const result = await response.json();
throw new Error(`Failed to get user status: ${result.message}`);
throw new Error(`Failed to get user info: ${result.message}`);
}

return (await response.json()) as UserStatus;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The response body is being consumed twice - once on line 35 with await response.json() and again on line 39. Since response bodies can only be read once, the second call will fail.

Consider storing the parsed JSON in a variable:

if (!response.ok) {
  const result = await response.json();
  throw new Error(`Failed to get user info: ${result.message}`);
}

const responseData = await response.json();
return responseData as UserStatus;

Or more concisely:

const responseData = await response.json();
if (!response.ok) {
  throw new Error(`Failed to get user info: ${responseData.message}`);
}
return responseData as UserStatus;
Suggested change
const result = await response.json();
throw new Error(`Failed to get user status: ${result.message}`);
throw new Error(`Failed to get user info: ${result.message}`);
}
return (await response.json()) as UserStatus;
const result = await response.json();
if (!response.ok) {
throw new Error(`Failed to get user info: ${result.message}`);
}
return result as UserStatus;

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

Copy link
Contributor

github-actions bot commented May 13, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 54.21 KB (0%) 1.1 s (0%) 545 ms (+722.13% 🔺) 1.7 s
thirdweb (cjs) 193.92 KB (0%) 3.9 s (0%) 709 ms (+168.22% 🔺) 4.6 s
thirdweb (minimal + tree-shaking) 5.68 KB (0%) 114 ms (0%) 426 ms (+8781.09% 🔺) 540 ms
thirdweb/chains (tree-shaking) 524 B (0%) 11 ms (0%) 39 ms (+1620.59% 🔺) 50 ms
thirdweb/react (minimal + tree-shaking) 19.53 KB (0%) 391 ms (0%) 400 ms (+2980.56% 🔺) 790 ms

Copy link

codecov bot commented May 14, 2025

Codecov Report

Attention: Patch coverage is 20.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 55.50%. Comparing base (1c31a1e) to head (1318c75).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...ets/in-app/core/actions/get-enclave-user-status.ts 20.00% 4 Missing ⚠️

❌ Your patch status has failed because the patch coverage (20.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7040      +/-   ##
==========================================
+ Coverage   54.89%   55.50%   +0.60%     
==========================================
  Files         909      909              
  Lines       58396    58402       +6     
  Branches     4035     4070      +35     
==========================================
+ Hits        32056    32415     +359     
+ Misses      26235    25882     -353     
  Partials      105      105              
Flag Coverage Δ
packages 55.50% <20.00%> (+0.60%) ⬆️
Files with missing lines Coverage Δ
...ets/in-app/core/actions/get-enclave-user-status.ts 78.57% <20.00%> (+2.70%) ⬆️

... and 16 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@joaquim-verges joaquim-verges merged commit 20b5ba9 into main May 14, 2025
23 of 24 checks passed
@joaquim-verges joaquim-verges deleted the Propagate_401_errors_when_connecting_in-app_wallet branch May 14, 2025 09:03
@joaquim-verges joaquim-verges mentioned this pull request May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
packages SDK Involves changes to the thirdweb SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant