@sasjs/adapter 6.1.5 → 6.1.7

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.
@@ -2400,6 +2400,7 @@ const SAS9AuthError_1 = __webpack_require__(2079);
2400
2400
  const utils_1 = __webpack_require__(9266);
2401
2401
  const InvalidSASjsCsrfError_1 = __webpack_require__(4001);
2402
2402
  const host_1 = __webpack_require__(5334);
2403
+ const responseReceived_1 = __webpack_require__(5775);
2403
2404
  const isNode_1 = __webpack_require__(6308);
2404
2405
  const mockReadiness_1 = __webpack_require__(2600);
2405
2406
  const MockReadinessError_1 = __webpack_require__(314);
@@ -2694,19 +2695,19 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
2694
2695
  throw (0, error_1.prefixMessage)(err, 'Error while executing callback in handleError. ');
2695
2696
  });
2696
2697
  }
2697
- throw e;
2698
+ throw (0, responseReceived_1.markResponseReceived)(e, true);
2698
2699
  }
2699
2700
  else if ((response === null || response === void 0 ? void 0 : response.status) === 404) {
2700
- throw new errors_1.NotFoundError(response.config.url);
2701
+ throw (0, responseReceived_1.markResponseReceived)(new errors_1.NotFoundError(response.config.url), true);
2701
2702
  }
2702
2703
  else if ((response === null || response === void 0 ? void 0 : response.status) === 502) {
2703
2704
  if (debug)
2704
- throw new errors_1.InternalServerError();
2705
+ throw (0, responseReceived_1.markResponseReceived)(new errors_1.InternalServerError(), true);
2705
2706
  else
2706
2707
  return;
2707
2708
  }
2708
2709
  if (e.isAxiosError && e.code === 'UNABLE_TO_VERIFY_LEAF_SIGNATURE') {
2709
- throw new errors_1.CertificateError(e.message);
2710
+ throw (0, responseReceived_1.markResponseReceived)(new errors_1.CertificateError(e.message), false);
2710
2711
  }
2711
2712
  if (e.isAxiosError &&
2712
2713
  !response &&
@@ -2731,18 +2732,20 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
2731
2732
  }
2732
2733
  return yield callback();
2733
2734
  }
2734
- catch (_b) {
2735
- // Session could not be recovered — surface LoginRequiredError
2736
- throw new errors_1.LoginRequiredError();
2735
+ catch (retryError) {
2736
+ // Session could not be recovered — surface LoginRequiredError. The
2737
+ // retry itself may have reached the server and been refused, which is
2738
+ // not the same as never arriving: the marker follows the retry's own
2739
+ // answer, not the opaque network error that started this.
2740
+ throw (0, responseReceived_1.markResponseReceived)(new errors_1.LoginRequiredError(), (0, responseReceived_1.responseWasReceived)(retryError));
2737
2741
  }
2738
2742
  finally {
2739
2743
  this.isRecoveringFromNetworkError = false;
2740
2744
  }
2741
2745
  }
2742
2746
  if (e.message)
2743
- throw e;
2744
- else
2745
- throw (0, error_1.prefixMessage)(e, 'Error while handling error. ');
2747
+ throw (0, responseReceived_1.markResponseReceived)(e, Boolean(response));
2748
+ throw (0, responseReceived_1.markResponseReceived)((0, error_1.prefixMessage)(e, 'Error while handling error. '), Boolean(response));
2746
2749
  });
2747
2750
  this.createHttpClient(baseUrl, httpsAgentOptions);
2748
2751
  if (requestsLimit)
@@ -3011,7 +3014,27 @@ exports.RequestClient = RequestClient;
3011
3014
  * included here.
3012
3015
  */
3013
3016
  const isTokenRefreshUrl = (url) => !!url && /(^|\/)auth\/refresh(\?|$)/.test(url);
3017
+ /**
3018
+ * Raises the error a response status implies, marked as one built from a
3019
+ * response.
3020
+ *
3021
+ * The marking has to happen here: every error below is a new object carrying
3022
+ * the body, so the axios error - the thing that knew a response had arrived -
3023
+ * is gone by the time a caller catches it (sasjs/adapter#895). A 401 from a
3024
+ * refresh route is named by `throwForStatus` as a rejected refresh token
3025
+ * (sasjs/adapter#975); this marks it as an answer that arrived, so a transport
3026
+ * failure and a refusal are not reported with the same title.
3027
+ */
3014
3028
  const throwIfError = (response) => {
3029
+ try {
3030
+ throwForStatus(response);
3031
+ }
3032
+ catch (error) {
3033
+ throw (0, responseReceived_1.markResponseReceived)(error, true);
3034
+ }
3035
+ };
3036
+ exports.throwIfError = throwIfError;
3037
+ const throwForStatus = (response) => {
3015
3038
  var _a, _b, _c, _d, _e, _f, _g, _h;
3016
3039
  switch (response.status) {
3017
3040
  case 400:
@@ -3063,7 +3086,6 @@ const throwIfError = (response) => {
3063
3086
  throw error;
3064
3087
  }
3065
3088
  };
3066
- exports.throwIfError = throwIfError;
3067
3089
  const parseError = (data) => {
3068
3090
  if (!data)
3069
3091
  return null;
@@ -3433,6 +3455,78 @@ const waitForMockReadiness = (ready, config) => __awaiter(void 0, void 0, void 0
3433
3455
  exports.waitForMockReadiness = waitForMockReadiness;
3434
3456
 
3435
3457
 
3458
+ /***/ },
3459
+
3460
+ /***/ 5775
3461
+ (__unused_webpack_module, exports) {
3462
+
3463
+ "use strict";
3464
+ var __webpack_unused_export__;
3465
+
3466
+ /**
3467
+ * Whether a failed request came back with an HTTP response.
3468
+ *
3469
+ * The request client turns a response into an error of its own - a 401 becomes a
3470
+ * `LoginRequiredError` carrying the body, a 404 a `NotFoundError` - so the axios
3471
+ * error, and with it the `response` property, is gone by the time a caller sees
3472
+ * the failure. That is why this cannot be inferred at the call site from the
3473
+ * error's shape: `throwIfError` has already replaced the shape.
3474
+ *
3475
+ * So the boundary stamps what it knows (`markResponseReceived`) and callers ask
3476
+ * this module. The `response` property is still the fallback, for errors that
3477
+ * never passed through the request client - but the marker wins when both are
3478
+ * present, because the boundary saw the response itself rather than a rebuilt
3479
+ * error that may or may not carry it.
3480
+ */
3481
+ __webpack_unused_export__ = ({ value: true });
3482
+ exports.responseWasReceived = exports.markResponseReceived = void 0;
3483
+ /** The property the request client leaves on an error it built. */
3484
+ const MARKER = 'responseReceived';
3485
+ /**
3486
+ * Records on an error whether the request it reports on came back with a
3487
+ * response. Returns the same error, so a throw site reads `throw mark(...)`.
3488
+ * Marks are kept but hidden: the error travels to the caller, where a new
3489
+ * enumerable field would show up in a log, a `JSON.stringify`, or a
3490
+ * deep-equality assertion against an unmarked copy - a difference nothing to do
3491
+ * with the request, reported as though it were.
3492
+ *
3493
+ * A frozen error cannot take the mark; it is returned unchanged and
3494
+ * `responseWasReceived` falls back to whatever `response` the error carries.
3495
+ */
3496
+ const markResponseReceived = (error, received) => {
3497
+ if (!error || (typeof error !== 'object' && typeof error !== 'function'))
3498
+ return error;
3499
+ try {
3500
+ Object.defineProperty(error, MARKER, {
3501
+ value: received,
3502
+ enumerable: false,
3503
+ configurable: true,
3504
+ writable: true
3505
+ });
3506
+ }
3507
+ catch (_a) {
3508
+ // not extensible: leave it unmarked rather than fail the request twice
3509
+ }
3510
+ return error;
3511
+ };
3512
+ exports.markResponseReceived = markResponseReceived;
3513
+ /**
3514
+ * Whether the failure behind this error came with an HTTP response.
3515
+ *
3516
+ * `false` is what a transport failure looks like: a wrong URL, a closed port, a
3517
+ * VPN that is down, a certificate that does not verify. The message that
3518
+ * accompanies such a failure is the transport's own (`connect ETIMEDOUT
3519
+ * 192.0.2.1:443`), not something a server said.
3520
+ */
3521
+ const responseWasReceived = (error) => {
3522
+ const marked = error === null || error === void 0 ? void 0 : error.responseReceived;
3523
+ if (typeof marked === 'boolean')
3524
+ return marked;
3525
+ return Boolean(error === null || error === void 0 ? void 0 : error.response);
3526
+ };
3527
+ exports.responseWasReceived = responseWasReceived;
3528
+
3529
+
3436
3530
  /***/ },
3437
3531
 
3438
3532
  /***/ 5777