Skip to content

Commit

Permalink
fix: provider rpc error parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Jan 14, 2025
1 parent 52366e8 commit ddaed51
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/giant-pillows-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ox": patch
---

Fixed parsing of Provider RPC errors.
2 changes: 2 additions & 0 deletions src/core/Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ export function parseErrorObject<
const errorObject_ = errorObject as RpcResponse.ErrorObject
const error = RpcResponse.parseErrorObject(errorObject_)
if (error instanceof RpcResponse.InternalError) {
if (!error.data) return error as never

const { code } = error.data as RpcResponse.ErrorObject
if (code === DisconnectedError.code)
return new DisconnectedError(errorObject_) as never
Expand Down
18 changes: 18 additions & 0 deletions src/core/_test/Provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,24 @@ describe('Provider.from', () => {
)
})

test('behavior: InternalError', async () => {
const provider = Provider.from({
async request(_) {
throw new RpcResponse.InternalError({
message: 'foo',
})
},
})

await expect(() =>
provider.request({
method: 'eth_blockNumber',
}),
).rejects.toThrowErrorMatchingInlineSnapshot(
'[RpcResponse.InternalError: Internal JSON-RPC error.]',
)
})

test('behavior: BaseError (raw)', async () => {
const provider = Provider.from({
async request(_) {
Expand Down

0 comments on commit ddaed51

Please sign in to comment.