snyk 1.758.0 → 1.759.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.
@@ -6632,7 +6632,6 @@ const lodash_omit_1 = __importDefault(__webpack_require__(76427));
6632
6632
  const files_1 = __webpack_require__(32083);
6633
6633
  const constants_1 = __webpack_require__(65765);
6634
6634
  const http_1 = __webpack_require__(60776);
6635
- const utils_1 = __webpack_require__(24054);
6636
6635
  const bundles_1 = __webpack_require__(86639);
6637
6636
  const emitter_1 = __webpack_require__(37544);
6638
6637
  const sleep = (duration) => new Promise(resolve => setTimeout(resolve, duration));
@@ -6683,10 +6682,11 @@ async function analyzeBundle(options) {
6683
6682
  exports.analyzeBundle = analyzeBundle;
6684
6683
  function normalizeResultFiles(files, baseDir) {
6685
6684
  if (baseDir) {
6686
- return (0, utils_1.fromEntries)(Object.entries(files).map(([path, positions]) => {
6685
+ return Object.entries(files).reduce((obj, [path, positions]) => {
6687
6686
  const filePath = (0, files_1.resolveBundleFilePath)(baseDir, path);
6688
- return [filePath, positions];
6689
- }));
6687
+ obj[filePath] = positions;
6688
+ return obj;
6689
+ }, {});
6690
6690
  }
6691
6691
  return files;
6692
6692
  }
@@ -6783,9 +6783,10 @@ function mergeSarifResults(oldAnalysisResults, newAnalysisResults, limitToFiles,
6783
6783
  }
6784
6784
  const moveSuggestionIndexes = (suggestionIndex, suggestions) => {
6785
6785
  const entries = Object.entries(suggestions);
6786
- return (0, utils_1.fromEntries)(entries.map(([i, s]) => {
6787
- return [`${parseInt(i, 10) + suggestionIndex + 1}`, s];
6788
- }));
6786
+ return entries.reduce((obj, [i, s]) => {
6787
+ obj[`${parseInt(i, 10) + suggestionIndex + 1}`] = s;
6788
+ return obj;
6789
+ }, {});
6789
6790
  };
6790
6791
  function mergeLegacyResults(oldAnalysisResults, newAnalysisResults, limitToFiles, removedFiles = [], baseDir) {
6791
6792
  // expand relative file names to absolute ones only for legacy results
@@ -6795,9 +6796,10 @@ function mergeLegacyResults(oldAnalysisResults, newAnalysisResults, limitToFiles
6795
6796
  // Addup all new suggestions' indexes
6796
6797
  const newSuggestions = moveSuggestionIndexes(suggestionIndex, newAnalysisResults.suggestions);
6797
6798
  const suggestions = { ...oldAnalysisResults.suggestions, ...newSuggestions };
6798
- const newFiles = (0, utils_1.fromEntries)(Object.entries(newAnalysisResults.files).map(([fn, s]) => {
6799
- return [fn, moveSuggestionIndexes(suggestionIndex, s)];
6800
- }));
6799
+ const newFiles = Object.entries(newAnalysisResults.files).reduce((obj, [fn, s]) => {
6800
+ obj[fn] = moveSuggestionIndexes(suggestionIndex, s);
6801
+ return obj;
6802
+ }, {});
6801
6803
  // expand relative file names to absolute ones only for legacy results
6802
6804
  const changedFiles = [...limitToFiles, ...removedFiles].map(path => (0, files_1.resolveBundleFilePath)(baseDir, path));
6803
6805
  const files = {
@@ -7119,7 +7121,7 @@ exports.readJSON = readJSON;
7119
7121
  "use strict";
7120
7122
 
7121
7123
  Object.defineProperty(exports, "__esModule", ({ value: true }));
7122
- exports.DEFAULT_ERROR_MESSAGES = exports.ErrorCodes = exports.DCIGNORE_DRAFTS = exports.IGNORE_FILES_NAMES = exports.IGNORES_DEFAULT = exports.REQUEST_RETRY_DELAY = exports.MAX_RETRY_ATTEMPTS = exports.POLLING_INTERVAL = exports.UPLOAD_CONCURRENCY = exports.MAX_UPLOAD_ATTEMPTS = exports.CACHE_KEY = exports.EXCLUDED_NAMES = exports.DOTSNYK_FILENAME = exports.DCIGNORE_FILENAME = exports.GITIGNORE_FILENAME = exports.GIT_FILENAME = exports.ENCODE_TYPE = exports.HASH_ALGORITHM = exports.defaultBaseURL = exports.MAX_FILE_SIZE = exports.MAX_PAYLOAD = void 0;
7124
+ exports.DEFAULT_ERROR_MESSAGES = exports.NETWORK_ERRORS = exports.ErrorCodes = exports.DCIGNORE_DRAFTS = exports.IGNORE_FILES_NAMES = exports.IGNORES_DEFAULT = exports.REQUEST_RETRY_DELAY = exports.MAX_RETRY_ATTEMPTS = exports.POLLING_INTERVAL = exports.UPLOAD_CONCURRENCY = exports.MAX_UPLOAD_ATTEMPTS = exports.CACHE_KEY = exports.EXCLUDED_NAMES = exports.DOTSNYK_FILENAME = exports.DCIGNORE_FILENAME = exports.GITIGNORE_FILENAME = exports.GIT_FILENAME = exports.ENCODE_TYPE = exports.HASH_ALGORITHM = exports.defaultBaseURL = exports.MAX_FILE_SIZE = exports.MAX_PAYLOAD = void 0;
7123
7125
  const dcignore_1 = __webpack_require__(55086);
7124
7126
  exports.MAX_PAYLOAD = 4 * 1024 * 1024;
7125
7127
  exports.MAX_FILE_SIZE = 128 * 1024;
@@ -7159,6 +7161,13 @@ var ErrorCodes;
7159
7161
  ErrorCodes[ErrorCodes["serviceUnavailable"] = 503] = "serviceUnavailable";
7160
7162
  ErrorCodes[ErrorCodes["timeout"] = 504] = "timeout";
7161
7163
  })(ErrorCodes = exports.ErrorCodes || (exports.ErrorCodes = {}));
7164
+ exports.NETWORK_ERRORS = {
7165
+ ETIMEDOUT: ErrorCodes.timeout,
7166
+ ECONNREFUSED: ErrorCodes.connectionRefused,
7167
+ ECONNRESET: ErrorCodes.connectionRefused,
7168
+ ENETUNREACH: ErrorCodes.connectionRefused,
7169
+ ENOTFOUND: ErrorCodes.dnsNotFound,
7170
+ };
7162
7171
  exports.DEFAULT_ERROR_MESSAGES = {
7163
7172
  [ErrorCodes.serverError]: 'Unexpected server error',
7164
7173
  [ErrorCodes.badGateway]: 'Bad gateway',
@@ -7654,34 +7663,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
7654
7663
  return (mod && mod.__esModule) ? mod : { "default": mod };
7655
7664
  };
7656
7665
  Object.defineProperty(exports, "__esModule", ({ value: true }));
7657
- exports.getAnalysis = exports.AnalysisStatus = exports.extendBundle = exports.checkBundle = exports.createBundle = exports.getFilters = exports.checkSession = exports.getIpFamily = exports.startSession = exports.determineErrorCode = void 0;
7666
+ exports.getAnalysis = exports.AnalysisStatus = exports.extendBundle = exports.checkBundle = exports.createBundle = exports.getFilters = exports.checkSession = exports.getIpFamily = exports.startSession = void 0;
7658
7667
  const uuid_1 = __webpack_require__(42277);
7659
7668
  const lodash_pick_1 = __importDefault(__webpack_require__(25030));
7660
7669
  const constants_1 = __webpack_require__(65765);
7661
7670
  const needle_1 = __webpack_require__(14577);
7662
- function determineErrorCode(error) {
7663
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
7664
- const { response } = error;
7665
- if (response) {
7666
- return response.statusCode;
7667
- }
7668
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
7669
- const { errno, code } = error;
7670
- if (errno === 'ECONNREFUSED') {
7671
- // set connectionRefused item
7672
- return constants_1.ErrorCodes.connectionRefused;
7673
- }
7674
- if (errno === 'ECONNRESET') {
7675
- // set connectionRefused item
7676
- return constants_1.ErrorCodes.connectionRefused;
7677
- }
7678
- if (code === 'ENOTFOUND') {
7679
- return constants_1.ErrorCodes.dnsNotFound;
7680
- }
7681
- // We must be strict here and if none of our existing logic recognized this error, just throw it up.
7682
- throw error;
7683
- }
7684
- exports.determineErrorCode = determineErrorCode;
7685
7671
  // The trick to typecast union type alias
7686
7672
  function isSubsetErrorCode(code, messages) {
7687
7673
  if (code in messages) {
@@ -7689,10 +7675,9 @@ function isSubsetErrorCode(code, messages) {
7689
7675
  }
7690
7676
  return false;
7691
7677
  }
7692
- function generateError(error, messages, apiName) {
7693
- const errorCode = determineErrorCode(error);
7678
+ function generateError(errorCode, messages, apiName) {
7694
7679
  if (!isSubsetErrorCode(errorCode, messages)) {
7695
- throw error;
7680
+ throw { errorCode, messages, apiName };
7696
7681
  }
7697
7682
  const statusCode = errorCode;
7698
7683
  const statusText = messages[errorCode];
@@ -7729,18 +7714,13 @@ exports.startSession = startSession;
7729
7714
  */
7730
7715
  async function getIpFamily(authHost) {
7731
7716
  const family = 6;
7732
- try {
7733
- // Dispatch a FORCED IPv6 request to test client's ISP and network capability
7734
- await (0, needle_1.makeRequest)({
7735
- url: `${authHost}/verify/callback`,
7736
- method: 'post',
7737
- family, // family param forces the handler to dispatch a request using IP at "family" version
7738
- });
7739
- return family;
7740
- }
7741
- catch (e) {
7742
- return undefined;
7743
- }
7717
+ // Dispatch a FORCED IPv6 request to test client's ISP and network capability
7718
+ const res = await (0, needle_1.makeRequest)({
7719
+ url: `${authHost}/verify/callback`,
7720
+ method: 'post',
7721
+ family, // family param forces the handler to dispatch a request using IP at "family" version
7722
+ }, 0);
7723
+ return res.success ? family : undefined;
7744
7724
  }
7745
7725
  exports.getIpFamily = getIpFamily;
7746
7726
  const CHECK_SESSION_ERROR_MESSAGES = {
@@ -7749,53 +7729,38 @@ const CHECK_SESSION_ERROR_MESSAGES = {
7749
7729
  [constants_1.ErrorCodes.loginInProgress]: constants_1.DEFAULT_ERROR_MESSAGES[constants_1.ErrorCodes.loginInProgress],
7750
7730
  };
7751
7731
  async function checkSession(options) {
7752
- var _a;
7753
7732
  const defaultValue = {
7754
7733
  type: 'success',
7755
7734
  value: '',
7756
7735
  };
7757
- try {
7758
- const { success, response } = await (0, needle_1.makeRequest)({
7759
- url: `${options.authHost}/api/v1/verify/callback`,
7760
- body: {
7761
- token: options.draftToken,
7762
- },
7763
- family: options.ipFamily,
7764
- method: 'post',
7765
- });
7766
- if (success) {
7767
- const responseBody = response.body;
7768
- defaultValue.value = (responseBody.ok && responseBody.api) || '';
7769
- }
7770
- return defaultValue;
7736
+ const res = await (0, needle_1.makeRequest)({
7737
+ url: `${options.authHost}/api/v1/verify/callback`,
7738
+ body: {
7739
+ token: options.draftToken,
7740
+ },
7741
+ family: options.ipFamily,
7742
+ method: 'post',
7743
+ });
7744
+ if (res.success) {
7745
+ return { ...defaultValue, value: (res.body.ok && res.body.api) || '' };
7771
7746
  }
7772
- catch (err) {
7773
- if ([constants_1.ErrorCodes.loginInProgress, constants_1.ErrorCodes.badRequest, constants_1.ErrorCodes.unauthorizedUser].includes(
7774
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
7775
- (_a = err.response) === null || _a === void 0 ? void 0 : _a.status)) {
7776
- return defaultValue;
7777
- }
7778
- return generateError(err, CHECK_SESSION_ERROR_MESSAGES, 'checkSession');
7747
+ else if ([constants_1.ErrorCodes.loginInProgress, constants_1.ErrorCodes.badRequest, constants_1.ErrorCodes.unauthorizedUser].includes(res.errorCode)) {
7748
+ return defaultValue;
7779
7749
  }
7750
+ return generateError(res.errorCode, CHECK_SESSION_ERROR_MESSAGES, 'checkSession');
7780
7751
  }
7781
7752
  exports.checkSession = checkSession;
7782
- async function getFilters(baseURL, source) {
7753
+ async function getFilters(baseURL, source, attempts = constants_1.MAX_RETRY_ATTEMPTS) {
7783
7754
  const apiName = 'filters';
7784
- try {
7785
- const { success, response } = await (0, needle_1.makeRequest)({
7786
- headers: { source },
7787
- url: `${baseURL}/${apiName}`,
7788
- method: 'get',
7789
- });
7790
- if (success) {
7791
- const responseBody = response.body;
7792
- return { type: 'success', value: responseBody };
7793
- }
7794
- return generateError({ response }, GENERIC_ERROR_MESSAGES, apiName);
7795
- }
7796
- catch (error) {
7797
- return generateError(error, GENERIC_ERROR_MESSAGES, 'filters');
7755
+ const res = await (0, needle_1.makeRequest)({
7756
+ headers: { source },
7757
+ url: `${baseURL}/${apiName}`,
7758
+ method: 'get',
7759
+ }, attempts);
7760
+ if (res.success) {
7761
+ return { type: 'success', value: res.body };
7798
7762
  }
7763
+ return generateError(res.errorCode, GENERIC_ERROR_MESSAGES, apiName);
7799
7764
  }
7800
7765
  exports.getFilters = getFilters;
7801
7766
  function prepareTokenHeaders(sessionToken) {
@@ -7814,25 +7779,20 @@ const CREATE_BUNDLE_ERROR_MESSAGES = {
7814
7779
  [constants_1.ErrorCodes.notFound]: 'Unable to resolve requested oid',
7815
7780
  };
7816
7781
  async function createBundle(options) {
7817
- try {
7818
- const payload = {
7819
- headers: {
7820
- ...prepareTokenHeaders(options.sessionToken),
7821
- source: options.source,
7822
- },
7823
- url: `${options.baseURL}/bundle`,
7824
- method: 'post',
7825
- body: options.files,
7826
- };
7827
- const { response, success } = await (0, needle_1.makeRequest)(payload);
7828
- if (success) {
7829
- return { type: 'success', value: response.body };
7830
- }
7831
- return generateError({ response }, CREATE_BUNDLE_ERROR_MESSAGES, 'createBundle');
7832
- }
7833
- catch (error) {
7834
- return generateError(error, CREATE_BUNDLE_ERROR_MESSAGES, 'createBundle');
7782
+ const payload = {
7783
+ headers: {
7784
+ ...prepareTokenHeaders(options.sessionToken),
7785
+ source: options.source,
7786
+ },
7787
+ url: `${options.baseURL}/bundle`,
7788
+ method: 'post',
7789
+ body: options.files,
7790
+ };
7791
+ const res = await (0, needle_1.makeRequest)(payload);
7792
+ if (res.success) {
7793
+ return { type: 'success', value: res.body };
7835
7794
  }
7795
+ return generateError(res.errorCode, CREATE_BUNDLE_ERROR_MESSAGES, 'createBundle');
7836
7796
  }
7837
7797
  exports.createBundle = createBundle;
7838
7798
  const CHECK_BUNDLE_ERROR_MESSAGES = {
@@ -7842,22 +7802,17 @@ const CHECK_BUNDLE_ERROR_MESSAGES = {
7842
7802
  [constants_1.ErrorCodes.notFound]: 'Uploaded bundle has expired',
7843
7803
  };
7844
7804
  async function checkBundle(options) {
7845
- try {
7846
- const { response, success } = await (0, needle_1.makeRequest)({
7847
- headers: {
7848
- ...prepareTokenHeaders(options.sessionToken),
7849
- source: options.source,
7850
- },
7851
- url: `${options.baseURL}/bundle/${options.bundleHash}`,
7852
- method: 'get',
7853
- });
7854
- if (success)
7855
- return { type: 'success', value: response.body };
7856
- return generateError({ response }, CHECK_BUNDLE_ERROR_MESSAGES, 'checkBundle');
7857
- }
7858
- catch (error) {
7859
- return generateError(error, CHECK_BUNDLE_ERROR_MESSAGES, 'checkBundle');
7860
- }
7805
+ const res = await (0, needle_1.makeRequest)({
7806
+ headers: {
7807
+ ...prepareTokenHeaders(options.sessionToken),
7808
+ source: options.source,
7809
+ },
7810
+ url: `${options.baseURL}/bundle/${options.bundleHash}`,
7811
+ method: 'get',
7812
+ });
7813
+ if (res.success)
7814
+ return { type: 'success', value: res.body };
7815
+ return generateError(res.errorCode, CHECK_BUNDLE_ERROR_MESSAGES, 'checkBundle');
7861
7816
  }
7862
7817
  exports.checkBundle = checkBundle;
7863
7818
  const EXTEND_BUNDLE_ERROR_MESSAGES = {
@@ -7869,23 +7824,18 @@ const EXTEND_BUNDLE_ERROR_MESSAGES = {
7869
7824
  [constants_1.ErrorCodes.notFound]: 'Parent bundle has expired',
7870
7825
  };
7871
7826
  async function extendBundle(options) {
7872
- try {
7873
- const { response, success } = await (0, needle_1.makeRequest)({
7874
- headers: {
7875
- ...prepareTokenHeaders(options.sessionToken),
7876
- source: options.source,
7877
- },
7878
- url: `${options.baseURL}/bundle/${options.bundleHash}`,
7879
- method: 'put',
7880
- body: (0, lodash_pick_1.default)(options, ['files', 'removedFiles']),
7881
- });
7882
- if (success)
7883
- return { type: 'success', value: response.body };
7884
- return generateError({ response }, EXTEND_BUNDLE_ERROR_MESSAGES, 'extendBundle');
7885
- }
7886
- catch (error) {
7887
- return generateError(error, EXTEND_BUNDLE_ERROR_MESSAGES, 'extendBundle');
7888
- }
7827
+ const res = await (0, needle_1.makeRequest)({
7828
+ headers: {
7829
+ ...prepareTokenHeaders(options.sessionToken),
7830
+ source: options.source,
7831
+ },
7832
+ url: `${options.baseURL}/bundle/${options.bundleHash}`,
7833
+ method: 'put',
7834
+ body: (0, lodash_pick_1.default)(options, ['files', 'removedFiles']),
7835
+ });
7836
+ if (res.success)
7837
+ return { type: 'success', value: res.body };
7838
+ return generateError(res.errorCode, EXTEND_BUNDLE_ERROR_MESSAGES, 'extendBundle');
7889
7839
  }
7890
7840
  exports.extendBundle = extendBundle;
7891
7841
  // eslint-disable-next-line no-shadow
@@ -7924,15 +7874,10 @@ async function getAnalysis(options) {
7924
7874
  ...(0, lodash_pick_1.default)(options, ['severity', 'prioritized', 'legacy']),
7925
7875
  },
7926
7876
  };
7927
- try {
7928
- const { response, success } = await (0, needle_1.makeRequest)(config);
7929
- if (success)
7930
- return { type: 'success', value: response.body };
7931
- return generateError({ response }, GET_ANALYSIS_ERROR_MESSAGES, 'getAnalysis');
7932
- }
7933
- catch (error) {
7934
- return generateError(error, GET_ANALYSIS_ERROR_MESSAGES, 'getAnalysis');
7935
- }
7877
+ const res = await (0, needle_1.makeRequest)(config);
7878
+ if (res.success)
7879
+ return { type: 'success', value: res.body };
7880
+ return generateError(res.errorCode, GET_ANALYSIS_ERROR_MESSAGES, 'getAnalysis');
7936
7881
  }
7937
7882
  exports.getAnalysis = getAnalysis;
7938
7883
  //# sourceMappingURL=http.js.map
@@ -8005,24 +7950,6 @@ var AnalysisSeverity;
8005
7950
 
8006
7951
  /***/ }),
8007
7952
 
8008
- /***/ 24054:
8009
- /***/ ((__unused_webpack_module, exports) => {
8010
-
8011
- "use strict";
8012
-
8013
- Object.defineProperty(exports, "__esModule", ({ value: true }));
8014
- exports.fromEntries = void 0;
8015
- function fromEntries(entries) {
8016
- return [...entries].reduce((obj, [key, val]) => {
8017
- obj[key] = val; // eslint-disable-line no-param-reassign
8018
- return obj;
8019
- }, {});
8020
- }
8021
- exports.fromEntries = fromEntries;
8022
- //# sourceMappingURL=utils.js.map
8023
-
8024
- /***/ }),
8025
-
8026
7953
  /***/ 14577:
8027
7954
  /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
8028
7955
 
@@ -8052,6 +7979,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
8052
7979
  };
8053
7980
  Object.defineProperty(exports, "__esModule", ({ value: true }));
8054
7981
  exports.makeRequest = void 0;
7982
+ /* eslint-disable camelcase */
8055
7983
  const http_1 = __importDefault(__webpack_require__(98605));
8056
7984
  const needle_1 = __importDefault(__webpack_require__(11642));
8057
7985
  const querystring = __importStar(__webpack_require__(71191));
@@ -8059,6 +7987,8 @@ const https_1 = __importDefault(__webpack_require__(57211));
8059
7987
  const url_1 = __webpack_require__(78835);
8060
7988
  const emitter_1 = __webpack_require__(37544);
8061
7989
  const constants_1 = __webpack_require__(65765);
7990
+ const sleep = (duration) => new Promise(resolve => setTimeout(resolve, duration));
7991
+ const TIMEOUT_DEFAULT = 10000;
8062
7992
  const agentOptions = {
8063
7993
  keepAlive: true,
8064
7994
  keepAliveMsecs: 1000,
@@ -8068,8 +7998,7 @@ const agentOptions = {
8068
7998
  socketActiveTTL: 1000 * 60 * 10,
8069
7999
  rejectUnauthorized: !global.ignoreUnknownCA,
8070
8000
  };
8071
- async function makeRequest(payload) {
8072
- var _a, _b;
8001
+ async function makeRequest(payload, attempts = constants_1.MAX_RETRY_ATTEMPTS) {
8073
8002
  const data = JSON.stringify(payload.body);
8074
8003
  const parsedUrl = new url_1.URL(payload.url);
8075
8004
  const agent = parsedUrl.protocol === 'http:' ? new http_1.default.Agent(agentOptions) : new https_1.default.Agent(agentOptions);
@@ -8084,9 +8013,9 @@ async function makeRequest(payload) {
8084
8013
  }
8085
8014
  const options = {
8086
8015
  headers: payload.headers,
8087
- open_timeout: 0,
8088
- response_timeout: payload.timeout,
8089
- read_timeout: payload.timeout,
8016
+ open_timeout: TIMEOUT_DEFAULT,
8017
+ response_timeout: payload.timeout || TIMEOUT_DEFAULT,
8018
+ read_timeout: payload.timeout || TIMEOUT_DEFAULT,
8090
8019
  family: payload.family,
8091
8020
  json: true,
8092
8021
  compressed: true,
@@ -8095,40 +8024,40 @@ async function makeRequest(payload) {
8095
8024
  agent,
8096
8025
  };
8097
8026
  emitter_1.emitter.apiRequestLog(`=> HTTP ${method === null || method === void 0 ? void 0 : method.toUpperCase()} ${url} ${data !== null && data !== void 0 ? data : ''}`.slice(0, 399));
8098
- let attempts = (_a = payload.attempts) !== null && _a !== void 0 ? _a : constants_1.MAX_RETRY_ATTEMPTS;
8099
- let retryDelay = (_b = payload.retryDelay) !== null && _b !== void 0 ? _b : constants_1.REQUEST_RETRY_DELAY;
8100
- let response, success;
8101
8027
  do {
8028
+ let errorCode;
8029
+ let response;
8102
8030
  try {
8103
8031
  response = await (0, needle_1.default)(method, url, data, options);
8104
8032
  emitter_1.emitter.apiRequestLog(`<= Response: ${response.statusCode} ${JSON.stringify(response.body)}`);
8105
- success = !!(response.statusCode && response.statusCode >= 200 && response.statusCode < 300);
8033
+ const success = !!(response.statusCode && response.statusCode >= 200 && response.statusCode < 300);
8106
8034
  if (success)
8107
- return { success, response };
8108
- // Try to avoid breaking requests due to temporary network errors
8109
- if (attempts > 1 && response.statusCode && [
8035
+ return { success, body: response.body };
8036
+ errorCode = response.statusCode;
8037
+ }
8038
+ catch (err) {
8039
+ errorCode = constants_1.NETWORK_ERRORS[err.code || err.errno];
8040
+ emitter_1.emitter.apiRequestLog(`Requested url --> ${url} | error --> ${err}`);
8041
+ }
8042
+ errorCode = errorCode !== null && errorCode !== void 0 ? errorCode : constants_1.ErrorCodes.serviceUnavailable;
8043
+ // Try to avoid breaking requests due to temporary network errors
8044
+ if (attempts > 1 &&
8045
+ [
8110
8046
  constants_1.ErrorCodes.serviceUnavailable,
8111
8047
  constants_1.ErrorCodes.badGateway,
8112
8048
  constants_1.ErrorCodes.connectionRefused,
8113
8049
  constants_1.ErrorCodes.timeout,
8114
8050
  constants_1.ErrorCodes.dnsNotFound,
8115
- ].includes(response.statusCode)) {
8116
- attempts--;
8117
- await new Promise(resolve => setTimeout(resolve, retryDelay));
8118
- }
8119
- else {
8120
- attempts = 0;
8121
- }
8051
+ ].includes(errorCode)) {
8052
+ attempts--;
8053
+ await sleep(constants_1.REQUEST_RETRY_DELAY);
8122
8054
  }
8123
- catch (err) {
8124
- emitter_1.emitter.apiRequestLog(`Request error --> ${err}`.slice(0, 399));
8125
- throw err;
8055
+ else {
8056
+ attempts = 0;
8057
+ return { success: false, errorCode };
8126
8058
  }
8127
8059
  } while (attempts > 0);
8128
- if (response)
8129
- return { success, response };
8130
- // Following line should be unreachable
8131
- throw new Error('Unknown network error');
8060
+ return { success: false, errorCode: constants_1.ErrorCodes.serviceUnavailable };
8132
8061
  }
8133
8062
  exports.makeRequest = makeRequest;
8134
8063
  //# sourceMappingURL=needle.js.map