@sanity/client 7.23.0 → 7.23.2

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.
@@ -419,6 +419,17 @@ const initConfig = (config, prevConfig) => {
419
419
  };
420
420
  class ConnectionFailedError extends Error {
421
421
  name = "ConnectionFailedError";
422
+ /**
423
+ * HTTP status code of the rejected connection attempt, if known.
424
+ * Only set when the EventSource implementation exposes it — the polyfill used in
425
+ * Node.js and when custom headers (eg authorization) are required does, while
426
+ * native EventSource implementations (browser and Node.js) do not.
427
+ */
428
+ status;
429
+ constructor(message, options = {}) {
430
+ const { status, ...errorOptions } = options;
431
+ super(message, errorOptions), this.status = status;
432
+ }
422
433
  }
423
434
  class DisconnectError extends Error {
424
435
  name = "DisconnectError";
@@ -462,6 +473,11 @@ function connectWithESInstance(es, events) {
462
473
  );
463
474
  return;
464
475
  }
476
+ const rawStatus = evt.status, status = typeof rawStatus == "number" ? rawStatus : void 0;
477
+ if (status !== void 0) {
478
+ observer.error(new ConnectionFailedError("EventSource connection failed", { status }));
479
+ return;
480
+ }
465
481
  es.readyState === es.CLOSED ? observer.error(new ConnectionFailedError("EventSource connection failed")) : emitReconnect && observer.next({ type: "reconnect" });
466
482
  }
467
483
  function onOpen() {
@@ -1433,11 +1449,11 @@ var defaults = (obj, defaults2) => Object.keys(defaults2).concat(Object.keys(obj
1433
1449
  const pick = (obj, props) => props.reduce((selection, prop) => (typeof obj[prop] > "u" || (selection[prop] = obj[prop]), selection), {}), eventSourcePolyfill = rxjs.defer(() => import("@sanity/eventsource")).pipe(
1434
1450
  operators.map(({ default: EventSource2 }) => EventSource2),
1435
1451
  rxjs.shareReplay(1)
1436
- );
1452
+ ), RETRYABLE_STATUSES = /* @__PURE__ */ new Set([408, 429]);
1437
1453
  function reconnectOnConnectionFailure() {
1438
1454
  return function(source) {
1439
1455
  return source.pipe(
1440
- rxjs.catchError((err, caught) => err instanceof ConnectionFailedError ? rxjs.concat(rxjs.of({ type: "reconnect" }), rxjs.timer(1e3).pipe(rxjs.mergeMap(() => caught))) : rxjs.throwError(() => err))
1456
+ rxjs.catchError((err, caught) => err instanceof ConnectionFailedError && (typeof err.status != "number" || err.status < 400 || err.status >= 500 || RETRYABLE_STATUSES.has(err.status)) ? rxjs.concat(rxjs.of({ type: "reconnect" }), rxjs.timer(1e3).pipe(rxjs.mergeMap(() => caught))) : rxjs.throwError(() => err))
1441
1457
  );
1442
1458
  };
1443
1459
  }