-
Notifications
You must be signed in to change notification settings - Fork 559
[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
[SDK] Propagate 401 errors when connecting in-app wallet #7040
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
🦋 Changeset detectedLatest commit: 1318c75 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
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. |
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; |
There was a problem hiding this comment.
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;
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.
packages/thirdweb/src/wallets/in-app/core/actions/get-enclave-user-status.ts
Show resolved
Hide resolved
size-limit report 📦
|
0f57dd8
to
1318c75
Compare
packages/thirdweb/src/wallets/in-app/core/actions/get-enclave-user-status.ts
Show resolved
Hide resolved
Codecov ReportAttention: Patch coverage is
❌ 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
🚀 New features to boost your workflow:
|
PR-Codex overview
This PR focuses on improving error handling in the
getUserStatus
function within theget-enclave-user-status.ts
file. It changes the way 401 errors are handled and modifies the return type of the function.Detailed summary
getUserStatus
fromPromise<UserStatus | undefined>
toPromise<UserStatus>
.undefined
when no user was logged in.response.text()
instead ofresponse.json()
.