Skip to content
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

update http quicknode rpc-provider #7102

Merged
merged 13 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/web3-providers-http/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,6 @@ Documentation:

- Fix issue lquixada/cross-fetch#78, enabling to run web3.js in service worker (#6463)

## [Unreleased]
## [Unreleased]

- returns LimitExceededError when code is 429 (#7102)
14 changes: 10 additions & 4 deletions packages/web3-providers-http/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import {
Web3APISpec,
Web3BaseProvider,
Web3ProviderStatus,
JsonRpcResponseWithError,
} from 'web3-types';
import { InvalidClientError, MethodNotImplementedError, ResponseError } from 'web3-errors';
import { InvalidClientError, MethodNotImplementedError, ResponseError, LimitExceededError } from 'web3-errors';
import { HttpProviderOptions } from './types.js';

export { HttpProviderOptions } from './types.js';
Expand Down Expand Up @@ -78,9 +79,14 @@ export default class HttpProvider<
},
body: JSON.stringify(payload),
});

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
if (!response.ok) throw new ResponseError(await response.json());
if (!response.ok) {
luu-alex marked this conversation as resolved.
Show resolved Hide resolved
const errResponse = (response as unknown as JsonRpcResponseWithError);
if (errResponse.error.code === 429) { // too many requests
throw new LimitExceededError(errResponse);
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
throw new ResponseError(await response.json())
};

return (await response.json()) as JsonRpcResponseWithResult<ResultType>;
}
Expand Down
Loading