Skip to content

Commit

Permalink
chore: 📝 Documentation of Error management
Browse files Browse the repository at this point in the history
  • Loading branch information
redDwarf03 committed Oct 1, 2024
1 parent fbab652 commit 282e7c7
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,29 @@ wagmi.Web3Modal.init(
wagmi.Web3Modal.open();
```

### Error management

Errors from wagmi can be handled using the `WagmiError` object.
Wagmi provides an error stack through the `cause` property.
The `findError` method with the error type allows checking if a specific error is in the error stack.

The different exceptions are available in the `WagmiErrors` enumeration

```dart
try {
final transactionHash = await wagmi.Core.writeContract(
parameters,
);
} on wagmi.WagmiError catch (e, stackTrace) {
if (e.findError(wagmi.WagmiErrors.UserRejectedRequestError) != null) {
throw Exception('userRejected');
}
if (e.findError(wagmi.WagmiErrors.InsufficientFundsError) != null) {
throw Exception('insufficientFunds');
}
throw Exception('${e.shortMessage}');
}
```

## Available Actions

Expand Down

0 comments on commit 282e7c7

Please sign in to comment.