Skip to content

Commit

Permalink
Quicknode provider error
Browse files Browse the repository at this point in the history
  • Loading branch information
jdevcs committed Aug 15, 2024
1 parent f5111a1 commit 7f6567c
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/web3-rpc-providers/src/web3_provider_quicknode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

import { EthExecutionAPI, JsonRpcResponseWithResult, Web3APIMethod, Web3APIPayload, Web3APIReturnType, Web3APISpec } from "web3-types";
import { ResponseError } from "web3-errors";
import { Transport, Network } from "./types.js";
import { Web3ExternalProvider } from "./web3_provider.js";
import { QuickNodeRateLimitError } from "./errors.js";

const isValid = (str: string) => str !== undefined && str.trim().length > 0;

export class QuickNodeProvider extends Web3ExternalProvider {
export class QuickNodeProvider<
API extends Web3APISpec = EthExecutionAPI,
> extends Web3ExternalProvider {

public constructor(
network: Network = Network.ETH_MAINNET,
Expand All @@ -32,6 +37,24 @@ export class QuickNodeProvider extends Web3ExternalProvider {

}

public async request<
Method extends Web3APIMethod<API>,
ResultType = Web3APIReturnType<API, Method>,
>(
payload: Web3APIPayload<EthExecutionAPI, Method>,
requestOptions?: RequestInit,
): Promise<JsonRpcResponseWithResult<ResultType>> {

try {
return await super.request(payload, requestOptions);
} catch (error) {
if (error instanceof ResponseError && error.statusCode === 429){
throw new QuickNodeRateLimitError(error);
}
throw error;
}
}

// eslint-disable-next-line class-methods-use-this
public getRPCURL(network: Network,
transport: Transport,
Expand Down

0 comments on commit 7f6567c

Please sign in to comment.