Skip to content

Commit

Permalink
fix(rpc): passing through a bad request error from the RPC provider (
Browse files Browse the repository at this point in the history
…#741)

* fix(rpc): adding proper handling of the bad request

* feat(tests): adding integration test

* fix: removing unnecessary comparing with the http 400
  • Loading branch information
geekbrother authored Aug 27, 2024
1 parent 9fe1d73 commit 1bbff5f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions integration/proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,21 @@ describe('Proxy', () => {
)
expect(resp.status).toBe(401)
})

it('Bad JSON-RPC request', async () => {
// Missing the id field
const payload = {
jsonrpc: "2.0",
method: "eth_chainId",
params: [],
};
const chainId = "eip155:11155111";

let resp: any = await httpClient.post(
`${baseUrl}/v1?chainId=${chainId}&projectId=${projectId}`,
payload
)
expect(resp.status).toBe(400)
expect(typeof resp.data).toBe('object')
})
})
2 changes: 1 addition & 1 deletion src/handlers/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ pub async fn rpc_provider_call(
);

match response.status() {
http::StatusCode::OK => {
http::StatusCode::OK | http::StatusCode::BAD_REQUEST => {
state.metrics.add_finished_provider_call(provider.borrow());
}
_ => {
Expand Down

0 comments on commit 1bbff5f

Please sign in to comment.