@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.mjs CHANGED
@@ -344,16 +344,17 @@ const httpRequestFunction = async function(axiosArgs, configuration) {
344
344
  else if (typeof responseData === "object") data = responseData;
345
345
  }
346
346
  const errorMsg = data.msg;
347
+ const errorCode = typeof data.code === "number" ? data.code : void 0;
347
348
  switch (status) {
348
- case 400: throw new BadRequestError(errorMsg);
349
- case 401: throw new UnauthorizedError(errorMsg);
350
- case 403: throw new ForbiddenError(errorMsg);
351
- case 404: throw new NotFoundError(errorMsg);
352
- case 418: throw new RateLimitBanError(errorMsg);
353
- case 429: throw new TooManyRequestsError(errorMsg);
349
+ case 400: throw new BadRequestError(errorMsg, errorCode);
350
+ case 401: throw new UnauthorizedError(errorMsg, errorCode);
351
+ case 403: throw new ForbiddenError(errorMsg, errorCode);
352
+ case 404: throw new NotFoundError(errorMsg, errorCode);
353
+ case 418: throw new RateLimitBanError(errorMsg, errorCode);
354
+ case 429: throw new TooManyRequestsError(errorMsg, errorCode);
354
355
  default:
355
356
  if (status >= 500 && status < 600) throw new ServerError(`Server error: ${status}`, status);
356
- throw new ConnectorClientError(errorMsg);
357
+ throw new ConnectorClientError(errorMsg, errorCode);
357
358
  }
358
359
  } else {
359
360
  if (retries > 0 && attempt >= retries) lastError = /* @__PURE__ */ new Error(`Request failed after ${retries} retries`);
@@ -730,10 +731,11 @@ const WALLET_REST_API_PROD_URL = "https://api.binance.com";
730
731
  * @param msg - An optional error message.
731
732
  */
732
733
  var ConnectorClientError = class ConnectorClientError extends Error {
733
- constructor(msg) {
734
+ constructor(msg, code) {
734
735
  super(msg || "An unexpected error occurred.");
735
736
  Object.setPrototypeOf(this, ConnectorClientError.prototype);
736
737
  this.name = "ConnectorClientError";
738
+ this.code = code;
737
739
  }
738
740
  };
739
741
  /**
@@ -754,10 +756,11 @@ var RequiredError = class RequiredError extends Error {
754
756
  * @param msg - An optional error message.
755
757
  */
756
758
  var UnauthorizedError = class UnauthorizedError extends Error {
757
- constructor(msg) {
759
+ constructor(msg, code) {
758
760
  super(msg || "Unauthorized access. Authentication required.");
759
761
  Object.setPrototypeOf(this, UnauthorizedError.prototype);
760
762
  this.name = "UnauthorizedError";
763
+ this.code = code;
761
764
  }
762
765
  };
763
766
  /**
@@ -765,10 +768,11 @@ var UnauthorizedError = class UnauthorizedError extends Error {
765
768
  * @param msg - An optional error message.
766
769
  */
767
770
  var ForbiddenError = class ForbiddenError extends Error {
768
- constructor(msg) {
771
+ constructor(msg, code) {
769
772
  super(msg || "Access to the requested resource is forbidden.");
770
773
  Object.setPrototypeOf(this, ForbiddenError.prototype);
771
774
  this.name = "ForbiddenError";
775
+ this.code = code;
772
776
  }
773
777
  };
774
778
  /**
@@ -776,10 +780,11 @@ var ForbiddenError = class ForbiddenError extends Error {
776
780
  * @param msg - An optional error message.
777
781
  */
778
782
  var TooManyRequestsError = class TooManyRequestsError extends Error {
779
- constructor(msg) {
783
+ constructor(msg, code) {
780
784
  super(msg || "Too many requests. You are being rate-limited.");
781
785
  Object.setPrototypeOf(this, TooManyRequestsError.prototype);
782
786
  this.name = "TooManyRequestsError";
787
+ this.code = code;
783
788
  }
784
789
  };
785
790
  /**
@@ -787,10 +792,11 @@ var TooManyRequestsError = class TooManyRequestsError extends Error {
787
792
  * @param msg - An optional error message.
788
793
  */
789
794
  var RateLimitBanError = class RateLimitBanError extends Error {
790
- constructor(msg) {
795
+ constructor(msg, code) {
791
796
  super(msg || "The IP address has been banned for exceeding rate limits.");
792
797
  Object.setPrototypeOf(this, RateLimitBanError.prototype);
793
798
  this.name = "RateLimitBanError";
799
+ this.code = code;
794
800
  }
795
801
  };
796
802
  /**
@@ -822,10 +828,11 @@ var NetworkError = class NetworkError extends Error {
822
828
  * @param msg - An optional error message.
823
829
  */
824
830
  var NotFoundError = class NotFoundError extends Error {
825
- constructor(msg) {
831
+ constructor(msg, code) {
826
832
  super(msg || "The requested resource was not found.");
827
833
  Object.setPrototypeOf(this, NotFoundError.prototype);
828
834
  this.name = "NotFoundError";
835
+ this.code = code;
829
836
  }
830
837
  };
831
838
  /**
@@ -833,10 +840,11 @@ var NotFoundError = class NotFoundError extends Error {
833
840
  * @param msg - An optional error message.
834
841
  */
835
842
  var BadRequestError = class BadRequestError extends Error {
836
- constructor(msg) {
843
+ constructor(msg, code) {
837
844
  super(msg || "The request was invalid or cannot be otherwise served.");
838
845
  Object.setPrototypeOf(this, BadRequestError.prototype);
839
846
  this.name = "BadRequestError";
847
+ this.code = code;
840
848
  }
841
849
  };
842
850