-
Notifications
You must be signed in to change notification settings - Fork 536
[SDK] Improve error handling in PayEmbed #7119
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] Improve error handling in PayEmbed #7119
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
🦋 Changeset detectedLatest commit: f83cbd2 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 |
## Walkthrough
This change introduces improved error handling for the "thirdweb" bridge modules by replacing generic error throws with a new structured `ApiError` class. The error reporting in various bridge-related functions now provides more detailed and consistent error information. Additionally, the number formatting in the PayWithCreditCard UI component was adjusted for better display precision. Some UI components related to error display for minimum amounts were simplified by removing conditional rendering and specialized buttons.
## Changes
| File(s) | Change Summary |
|------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `.changeset/blue-comics-doubt.md` | Documents the patch update, summarizing improvements to error messages in the PayEmbed functionality of the "thirdweb" component. |
| `packages/thirdweb/src/bridge/Buy.ts`<br>`.../Sell.ts`<br>`.../Onramp.ts`<br>`.../Transfer.ts`<br>`.../Status.ts`<br>`.../OnrampStatus.ts`<br>`.../Chains.ts`<br>`.../Routes.ts` | Updated error handling in bridge-related functions to throw a new `ApiError` with structured properties (`code`, `message`, `correlationId`, `statusCode`) instead of generic `Error` objects. The thrown errors now contain richer, more consistent information extracted from the API response. |
| `packages/thirdweb/src/bridge/types/Errors.ts` | Introduced new error type definitions: `ErrorCode` union type and `ApiError` class, which extends the built-in `Error` class and adds fields for code, correlation ID, and status code. |
| `packages/thirdweb/src/react/web/utils/errors.ts` | Enhanced the `getErrorMessage` function to specifically handle `ApiError` instances, returning a structured `UiError` object with a cleaned-up message. Added a helper function to sanitize error messages from `ApiError`. |
| `packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/PayWIthCreditCard.tsx` | Changed numeric display formatting in `PayWithCreditCard` component from 6 to 2 decimal places for improved value presentation. |
| `packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatScreenContent.tsx`| Removed conditional rendering of minimum amount error messages and "Set Minimum" button; simplified error display to a generic message and always render a single "Continue" button. |
| `packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/SwapScreenContent.tsx`| Removed conditional rendering for minimum amount error messages and "Set Minimum" button; simplified error display to always show error title and message, and changed button logic to show "Pay with another token" only if error or insufficient balance. |
| `packages/thirdweb/src/bridge/Routes.test.ts` | Updated test expectation for error message in invalid route request test to match new error message format without error code prefix. |
| `packages/thirdweb/src/bridge/index.ts` | Renamed export of type `BridgeAction` to `Action` and added export of the `ApiError` class from the `types/Errors` module. |
| `packages/thirdweb/src/bridge/types/BridgeAction.ts` | Renamed exported type alias from `BridgeAction` to `Action` without changing the underlying union string literal values. |
| `packages/thirdweb/src/bridge/types/Route.ts` | Updated import and type annotation for `action` property in `RouteTransaction` from `BridgeAction` to `Action`. |
## Sequence Diagram(s)
```mermaid
sequenceDiagram
participant UI
participant BridgeModule
participant API
UI->>BridgeModule: Call bridge function (e.g., quote, prepare)
BridgeModule->>API: Send HTTP request
API-->>BridgeModule: Respond (success or error)
alt Response is OK
BridgeModule-->>UI: Return result
else Response is Error
BridgeModule->>ApiError: Construct with code, message, correlationId, statusCode
BridgeModule-->>UI: Throw ApiError
end
UI->>getErrorMessage: Handle error
getErrorMessage-->>UI: Return structured UiError Suggested reviewers
|
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. |
size-limit report 📦
|
6c38672
to
b0bd643
Compare
Codecov ReportAttention: Patch coverage is
❌ Your patch status has failed because the patch coverage (32.11%) 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 #7119 +/- ##
==========================================
+ Coverage 55.59% 55.62% +0.02%
==========================================
Files 901 902 +1
Lines 58121 58135 +14
Branches 4068 4087 +19
==========================================
+ Hits 32315 32337 +22
+ Misses 25701 25693 -8
Partials 105 105
🚀 New features to boost your workflow:
|
b0bd643
to
95c2dd0
Compare
95c2dd0
to
e5f406d
Compare
e5f406d
to
f83cbd2
Compare
PR-Codex overview
This PR focuses on improving error handling and messages within the
thirdweb
package, particularly in thePayEmbed
component and throughout the bridge-related functionalities. It introduces a newApiError
class for more structured error management.Detailed summary
PayEmbed
.ApiError
class inpackages/thirdweb/src/bridge/types/Errors.ts
.ApiError
in various files.BridgeAction
toAction
in type definitions.SwapScreenContent
andFiatScreenContent
.Summary by CodeRabbit