Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 1f8cb47

Browse files
author
Dan Forbes
authored
Merge branch '4.x' into feat/docs/external-provider
2 parents 181a86d + 4f8e8cc commit 1f8cb47

File tree

15 files changed

+264
-73
lines changed

15 files changed

+264
-73
lines changed

packages/web3-errors/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,8 @@ Documentation:
178178

179179
- Fixed the undefined data in `Eip838ExecutionError` constructor (#6905)
180180

181-
## [Unreleased]
181+
## [Unreleased]
182+
183+
### Added
184+
185+
- Added optional `statusCode` property of response in ResponseError.

packages/web3-errors/src/errors/response_errors.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ export class ResponseError<ErrorType = unknown, RequestType = unknown> extends B
4545
public code = ERR_RESPONSE;
4646
public data?: ErrorType | ErrorType[];
4747
public request?: JsonRpcPayload<RequestType>;
48+
public statusCode?: number;
4849

4950
public constructor(
5051
response: JsonRpcResponse<unknown, ErrorType>,
5152
message?: string,
5253
request?: JsonRpcPayload<RequestType>,
54+
statusCode?: number
5355
) {
5456
super(
5557
message ??
@@ -66,6 +68,7 @@ export class ResponseError<ErrorType = unknown, RequestType = unknown> extends B
6668
: response?.error?.data;
6769
}
6870

71+
this.statusCode = statusCode;
6972
this.request = request;
7073
let errorOrErrors: JsonRpcError | JsonRpcError[] | undefined;
7174
if (`error` in response) {
@@ -82,7 +85,7 @@ export class ResponseError<ErrorType = unknown, RequestType = unknown> extends B
8285
}
8386

8487
public toJSON() {
85-
return { ...super.toJSON(), data: this.data, request: this.request };
88+
return { ...super.toJSON(), data: this.data, request: this.request, statusCode: this.statusCode };
8689
}
8790
}
8891

packages/web3-errors/test/unit/__snapshots__/errors.test.ts.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ exports[`errors InvalidResponseError should have valid json structure 1`] = `
239239
"message": "Returned error: error message",
240240
"name": "InvalidResponseError",
241241
"request": undefined,
242+
"statusCode": undefined,
242243
}
243244
`;
244245

@@ -316,6 +317,7 @@ exports[`errors ResponseError should have valid json structure with data 1`] = `
316317
"message": "Returned error: error message",
317318
"name": "ResponseError",
318319
"request": undefined,
320+
"statusCode": undefined,
319321
}
320322
`;
321323

@@ -336,6 +338,7 @@ exports[`errors ResponseError should have valid json structure without data 1`]
336338
"message": "Returned error: error message",
337339
"name": "ResponseError",
338340
"request": undefined,
341+
"statusCode": undefined,
339342
}
340343
`;
341344

@@ -357,6 +360,7 @@ exports[`errors ResponseError should include the array of inner errors 1`] = `
357360
"message": "Returned error: error message,error message",
358361
"name": "ResponseError",
359362
"request": undefined,
363+
"statusCode": undefined,
360364
}
361365
`;
362366

packages/web3-providers-http/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,8 @@ Documentation:
129129

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

132-
## [Unreleased]
132+
## [Unreleased]
133+
134+
### Added
135+
136+
- Added `statusCode` of response in ResponseError, `statusCode` is optional property in ResponseError.

packages/web3-providers-http/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default class HttpProvider<
8080
});
8181
if (!response.ok) {
8282
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
83-
throw new ResponseError(await response.json())
83+
throw new ResponseError(await response.json(), undefined, undefined, response.status);
8484
};
8585

8686
return (await response.json()) as JsonRpcResponseWithResult<ResultType>;

packages/web3-rpc-providers/CHANGELOG.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4343

4444
## [1.0.0.rc.1]
4545

46-
### Added
46+
### Added
4747

4848
- When error is returned with code 429, throw rate limit error (#7102)
4949

50-
### Changed
50+
### Changed
5151

5252
- Change request return type `Promise<ResultType>` to `Promise<JsonRpcResponseWithResult<ResultType>>` (#7102)
5353

54-
## [Unreleased]
54+
## [Unreleased]
55+
56+
### Added
57+
58+
- Updated rate limit error of QuickNode provider for HTTP transport
59+
- Added optional `HttpProviderOptions | SocketOptions` in `Web3ExternalProvider` and `QuickNodeProvider` for provider configs

packages/web3-rpc-providers/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"eslint-config-base-web3": "0.1.0",
5050
"eslint-config-prettier": "^8.5.0",
5151
"eslint-plugin-import": "^2.26.0",
52+
"isomorphic-ws": "^5.0.0",
5253
"jest": "^29.7.0",
5354
"jest-extended": "^3.0.1",
5455
"prettier": "^2.7.1",

packages/web3-rpc-providers/src/errors.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,25 @@ You should have received a copy of the GNU Lesser General Public License
1515
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18+
/* eslint-disable max-classes-per-file */
19+
1820
import { BaseWeb3Error } from 'web3-errors';
19-
import { } from 'web3-types';
2021

2122
const ERR_QUICK_NODE_RATE_LIMIT = 1300;
2223
export class QuickNodeRateLimitError extends BaseWeb3Error {
2324
public code = ERR_QUICK_NODE_RATE_LIMIT;
2425

25-
public constructor() {
26-
super(`Too many requests, Quicknode has reached its rate limit.`);
26+
public constructor(error?: Error) {
27+
super(`You've reach the rate limit of free RPC calls from our Partner Quick Nodes. There are two options you can either create a paid Quick Nodes account and get 20% off for 2 months using WEB3JS referral code, or use Free public RPC endpoint.`, error);
28+
}
29+
}
30+
31+
const ERR_PROVIDER_CONFIG_OPTIONS = 1301;
32+
export class ProviderConfigOptionsError extends BaseWeb3Error {
33+
public code = ERR_PROVIDER_CONFIG_OPTIONS;
34+
35+
public constructor(msg: string) {
36+
super(`Invalid provider config options given for ${msg}`);
2737
}
28-
}
38+
}
39+
/* eslint-enable max-classes-per-file */

packages/web3-rpc-providers/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { QuickNodeProvider } from './web3_provider_quicknode.js';
2020
export * from './types.js';
2121
export * from './web3_provider_quicknode.js';
2222
export * from './web3_provider.js';
23+
export * from './errors.js';
2324

2425
// default providers
2526
export const mainnet = new QuickNodeProvider();

packages/web3-rpc-providers/src/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ You should have received a copy of the GNU Lesser General Public License
1515
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18+
import {ClientOptions, ClientRequestArgs} from "web3-providers-ws";
19+
import { ReconnectOptions } from 'web3-utils';
20+
1821
export enum Transport {
1922
HTTPS = "https",
2023
WebSocket = "wss"
@@ -41,4 +44,10 @@ export enum Network {
4144

4245
BNB_MAINNET = "bnb_mainnet",
4346
BNB_TESTNET = "bnb_testnet"
47+
};
48+
49+
// Combining the ws types
50+
export type SocketOptions = {
51+
socketOptions?: ClientOptions | ClientRequestArgs;
52+
reconnectOptions?: Partial<ReconnectOptions>;
4453
};

0 commit comments

Comments
 (0)