diff --git a/packages/medusa-plugin-brightpearl/src/utils/brightpearl.js b/packages/medusa-plugin-brightpearl/src/utils/brightpearl.js index b549430d9b..4e885f19fe 100644 --- a/packages/medusa-plugin-brightpearl/src/utils/brightpearl.js +++ b/packages/medusa-plugin-brightpearl/src/utils/brightpearl.js @@ -93,6 +93,7 @@ class BrightpearlClient { this.client_.interceptors.response.use(undefined, async (error) => { const response = error.response + console.log(response) if (response) { if ( diff --git a/packages/medusa-plugin-brightpearl/utils/brightpearl.js b/packages/medusa-plugin-brightpearl/utils/brightpearl.js index 26945a0f0e..acf8b6b810 100644 --- a/packages/medusa-plugin-brightpearl/utils/brightpearl.js +++ b/packages/medusa-plugin-brightpearl/utils/brightpearl.js @@ -7,6 +7,8 @@ exports["default"] = void 0; var _axios = _interopRequireDefault(require("axios")); +var _axiosRateLimit = _interopRequireDefault(require("axios-rate-limit")); + var _querystring = _interopRequireDefault(require("querystring")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } @@ -25,6 +27,10 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +// Brightpearl allows 200 requests per minute +var RATE_LIMIT_REQUESTS = 200; +var RATE_LIMIT_INTERVAL = 60 * 1000; + var BrightpearlClient = /*#__PURE__*/function () { _createClass(BrightpearlClient, null, [{ key: "createToken", @@ -282,12 +288,15 @@ var BrightpearlClient = /*#__PURE__*/function () { }; }); - this.client_ = _axios["default"].create({ + this.client_ = (0, _axiosRateLimit["default"])(_axios["default"].create({ baseURL: "https://".concat(options.url, "/public-api/").concat(options.account), headers: { "brightpearl-app-ref": "medusa-dev", "brightpearl-dev-ref": "sebrindom" } + }), { + maxRequests: RATE_LIMIT_REQUESTS, + perMilliseconds: RATE_LIMIT_INTERVAL }); this.authType_ = options.auth_type; this.token_ = options.access_token;