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
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