Error Handling
The error
property in Wagmi Hooks is strongly typed with it's corresponding error type. This enables you to have granular precision with handling errors in your application.
You can discriminate the error type by using the name
property on the error object.
tsx
import { } from 'wagmi'
function () {
const { , } = ()
?.
if (?. === 'HttpRequestError') {
const { } =
return <>A HTTP error occurred. Status: {}</>
}
if (?. === 'LimitExceededRpcError') {
const { } =
return <>Rate limit exceeded. Code: {}</>
}
// ...
}
ts
import { http, createConfig } from 'wagmi'
import { mainnet, sepolia } from 'wagmi/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})