@binance/common 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -312,7 +312,8 @@ declare class ConfigurationWebsocketStreams {
312
312
  * @param msg - An optional error message.
313
313
  */
314
314
  declare class ConnectorClientError extends Error {
315
- constructor(msg?: string);
315
+ code?: number;
316
+ constructor(msg?: string, code?: number);
316
317
  }
317
318
  /**
318
319
  * Represents an error that occurs when a required parameter is missing or undefined.
@@ -328,28 +329,32 @@ declare class RequiredError extends Error {
328
329
  * @param msg - An optional error message.
329
330
  */
330
331
  declare class UnauthorizedError extends Error {
331
- constructor(msg?: string);
332
+ code?: number;
333
+ constructor(msg?: string, code?: number);
332
334
  }
333
335
  /**
334
336
  * Represents an error that occurs when a resource is forbidden to the client.
335
337
  * @param msg - An optional error message.
336
338
  */
337
339
  declare class ForbiddenError extends Error {
338
- constructor(msg?: string);
340
+ code?: number;
341
+ constructor(msg?: string, code?: number);
339
342
  }
340
343
  /**
341
344
  * Represents an error that occurs when client is doing too many requests.
342
345
  * @param msg - An optional error message.
343
346
  */
344
347
  declare class TooManyRequestsError extends Error {
345
- constructor(msg?: string);
348
+ code?: number;
349
+ constructor(msg?: string, code?: number);
346
350
  }
347
351
  /**
348
352
  * Represents an error that occurs when client's IP has been banned.
349
353
  * @param msg - An optional error message.
350
354
  */
351
355
  declare class RateLimitBanError extends Error {
352
- constructor(msg?: string);
356
+ code?: number;
357
+ constructor(msg?: string, code?: number);
353
358
  }
354
359
  /**
355
360
  * Represents an error that occurs when there is an internal server error.
@@ -372,14 +377,16 @@ declare class NetworkError extends Error {
372
377
  * @param msg - An optional error message.
373
378
  */
374
379
  declare class NotFoundError extends Error {
375
- constructor(msg?: string);
380
+ code?: number;
381
+ constructor(msg?: string, code?: number);
376
382
  }
377
383
  /**
378
384
  * Represents an error that occurs when a request is invalid or cannot be otherwise served.
379
385
  * @param msg - An optional error message.
380
386
  */
381
387
  declare class BadRequestError extends Error {
382
- constructor(msg?: string);
388
+ code?: number;
389
+ constructor(msg?: string, code?: number);
383
390
  }
384
391
  //#endregion
385
392
  //#region src/logger.d.ts
package/dist/index.d.ts CHANGED
@@ -312,7 +312,8 @@ declare class ConfigurationWebsocketStreams {
312
312
  * @param msg - An optional error message.
313
313
  */
314
314
  declare class ConnectorClientError extends Error {
315
- constructor(msg?: string);
315
+ code?: number;
316
+ constructor(msg?: string, code?: number);
316
317
  }
317
318
  /**
318
319
  * Represents an error that occurs when a required parameter is missing or undefined.
@@ -328,28 +329,32 @@ declare class RequiredError extends Error {
328
329
  * @param msg - An optional error message.
329
330
  */
330
331
  declare class UnauthorizedError extends Error {
331
- constructor(msg?: string);
332
+ code?: number;
333
+ constructor(msg?: string, code?: number);
332
334
  }
333
335
  /**
334
336
  * Represents an error that occurs when a resource is forbidden to the client.
335
337
  * @param msg - An optional error message.
336
338
  */
337
339
  declare class ForbiddenError extends Error {
338
- constructor(msg?: string);
340
+ code?: number;
341
+ constructor(msg?: string, code?: number);
339
342
  }
340
343
  /**
341
344
  * Represents an error that occurs when client is doing too many requests.
342
345
  * @param msg - An optional error message.
343
346
  */
344
347
  declare class TooManyRequestsError extends Error {
345
- constructor(msg?: string);
348
+ code?: number;
349
+ constructor(msg?: string, code?: number);
346
350
  }
347
351
  /**
348
352
  * Represents an error that occurs when client's IP has been banned.
349
353
  * @param msg - An optional error message.
350
354
  */
351
355
  declare class RateLimitBanError extends Error {
352
- constructor(msg?: string);
356
+ code?: number;
357
+ constructor(msg?: string, code?: number);
353
358
  }
354
359
  /**
355
360
  * Represents an error that occurs when there is an internal server error.
@@ -372,14 +377,16 @@ declare class NetworkError extends Error {
372
377
  * @param msg - An optional error message.
373
378
  */
374
379
  declare class NotFoundError extends Error {
375
- constructor(msg?: string);
380
+ code?: number;
381
+ constructor(msg?: string, code?: number);
376
382
  }
377
383
  /**
378
384
  * Represents an error that occurs when a request is invalid or cannot be otherwise served.
379
385
  * @param msg - An optional error message.
380
386
  */
381
387
  declare class BadRequestError extends Error {
382
- constructor(msg?: string);
388
+ code?: number;
389
+ constructor(msg?: string, code?: number);
383
390
  }
384
391
  //#endregion
385
392
  //#region src/logger.d.ts
package/dist/index.js CHANGED
@@ -372,16 +372,17 @@ const httpRequestFunction = async function(axiosArgs, configuration) {
372
372
  else if (typeof responseData === "object") data = responseData;
373
373
  }
374
374
  const errorMsg = data.msg;
375
+ const errorCode = typeof data.code === "number" ? data.code : void 0;
375
376
  switch (status) {
376
- case 400: throw new BadRequestError(errorMsg);
377
- case 401: throw new UnauthorizedError(errorMsg);
378
- case 403: throw new ForbiddenError(errorMsg);
379
- case 404: throw new NotFoundError(errorMsg);
380
- case 418: throw new RateLimitBanError(errorMsg);
381
- case 429: throw new TooManyRequestsError(errorMsg);
377
+ case 400: throw new BadRequestError(errorMsg, errorCode);
378
+ case 401: throw new UnauthorizedError(errorMsg, errorCode);
379
+ case 403: throw new ForbiddenError(errorMsg, errorCode);
380
+ case 404: throw new NotFoundError(errorMsg, errorCode);
381
+ case 418: throw new RateLimitBanError(errorMsg, errorCode);
382
+ case 429: throw new TooManyRequestsError(errorMsg, errorCode);
382
383
  default:
383
384
  if (status >= 500 && status < 600) throw new ServerError(`Server error: ${status}`, status);
384
- throw new ConnectorClientError(errorMsg);
385
+ throw new ConnectorClientError(errorMsg, errorCode);
385
386
  }
386
387
  } else {
387
388
  if (retries > 0 && attempt >= retries) lastError = /* @__PURE__ */ new Error(`Request failed after ${retries} retries`);
@@ -758,10 +759,11 @@ const WALLET_REST_API_PROD_URL = "https://api.binance.com";
758
759
  * @param msg - An optional error message.
759
760
  */
760
761
  var ConnectorClientError = class ConnectorClientError extends Error {
761
- constructor(msg) {
762
+ constructor(msg, code) {
762
763
  super(msg || "An unexpected error occurred.");
763
764
  Object.setPrototypeOf(this, ConnectorClientError.prototype);
764
765
  this.name = "ConnectorClientError";
766
+ this.code = code;
765
767
  }
766
768
  };
767
769
  /**
@@ -782,10 +784,11 @@ var RequiredError = class RequiredError extends Error {
782
784
  * @param msg - An optional error message.
783
785
  */
784
786
  var UnauthorizedError = class UnauthorizedError extends Error {
785
- constructor(msg) {
787
+ constructor(msg, code) {
786
788
  super(msg || "Unauthorized access. Authentication required.");
787
789
  Object.setPrototypeOf(this, UnauthorizedError.prototype);
788
790
  this.name = "UnauthorizedError";
791
+ this.code = code;
789
792
  }
790
793
  };
791
794
  /**
@@ -793,10 +796,11 @@ var UnauthorizedError = class UnauthorizedError extends Error {
793
796
  * @param msg - An optional error message.
794
797
  */
795
798
  var ForbiddenError = class ForbiddenError extends Error {
796
- constructor(msg) {
799
+ constructor(msg, code) {
797
800
  super(msg || "Access to the requested resource is forbidden.");
798
801
  Object.setPrototypeOf(this, ForbiddenError.prototype);
799
802
  this.name = "ForbiddenError";
803
+ this.code = code;
800
804
  }
801
805
  };
802
806
  /**
@@ -804,10 +808,11 @@ var ForbiddenError = class ForbiddenError extends Error {
804
808
  * @param msg - An optional error message.
805
809
  */
806
810
  var TooManyRequestsError = class TooManyRequestsError extends Error {
807
- constructor(msg) {
811
+ constructor(msg, code) {
808
812
  super(msg || "Too many requests. You are being rate-limited.");
809
813
  Object.setPrototypeOf(this, TooManyRequestsError.prototype);
810
814
  this.name = "TooManyRequestsError";
815
+ this.code = code;
811
816
  }
812
817
  };
813
818
  /**
@@ -815,10 +820,11 @@ var TooManyRequestsError = class TooManyRequestsError extends Error {
815
820
  * @param msg - An optional error message.
816
821
  */
817
822
  var RateLimitBanError = class RateLimitBanError extends Error {
818
- constructor(msg) {
823
+ constructor(msg, code) {
819
824
  super(msg || "The IP address has been banned for exceeding rate limits.");
820
825
  Object.setPrototypeOf(this, RateLimitBanError.prototype);
821
826
  this.name = "RateLimitBanError";
827
+ this.code = code;
822
828
  }
823
829
  };
824
830
  /**
@@ -850,10 +856,11 @@ var NetworkError = class NetworkError extends Error {
850
856
  * @param msg - An optional error message.
851
857
  */
852
858
  var NotFoundError = class NotFoundError extends Error {
853
- constructor(msg) {
859
+ constructor(msg, code) {
854
860
  super(msg || "The requested resource was not found.");
855
861
  Object.setPrototypeOf(this, NotFoundError.prototype);
856
862
  this.name = "NotFoundError";
863
+ this.code = code;
857
864
  }
858
865
  };
859
866
  /**
@@ -861,10 +868,11 @@ var NotFoundError = class NotFoundError extends Error {
861
868
  * @param msg - An optional error message.
862
869
  */
863
870
  var BadRequestError = class BadRequestError extends Error {
864
- constructor(msg) {
871
+ constructor(msg, code) {
865
872
  super(msg || "The request was invalid or cannot be otherwise served.");
866
873
  Object.setPrototypeOf(this, BadRequestError.prototype);
867
874
  this.name = "BadRequestError";
875
+ this.code = code;
868
876
  }
869
877
  };
870
878