@getanyapi/sdk 0.178.19 → 0.179.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.d.cts CHANGED
@@ -485,8 +485,14 @@ declare class NotFoundError extends AnyAPIError {
485
485
  */
486
486
  declare class ResultNotFoundError extends NotFoundError {
487
487
  }
488
- /** HTTP 429. */
488
+ /**
489
+ * HTTP 429. `retryAfterSeconds` is the response's Retry-After when it carried one: wait that
490
+ * long before sending again. Code `rate_limited` on a run means the account reached its limit
491
+ * of new requests a minute to that API; nothing was run or charged.
492
+ */
489
493
  declare class RateLimitedError extends AnyAPIError {
494
+ readonly retryAfterSeconds?: number;
495
+ constructor(message: string, status: number, requestId?: string, code?: string, retryAfterSeconds?: number);
490
496
  }
491
497
  /** HTTP 502. */
492
498
  declare class UpstreamError extends AnyAPIError {
package/dist/index.d.ts CHANGED
@@ -485,8 +485,14 @@ declare class NotFoundError extends AnyAPIError {
485
485
  */
486
486
  declare class ResultNotFoundError extends NotFoundError {
487
487
  }
488
- /** HTTP 429. */
488
+ /**
489
+ * HTTP 429. `retryAfterSeconds` is the response's Retry-After when it carried one: wait that
490
+ * long before sending again. Code `rate_limited` on a run means the account reached its limit
491
+ * of new requests a minute to that API; nothing was run or charged.
492
+ */
489
493
  declare class RateLimitedError extends AnyAPIError {
494
+ readonly retryAfterSeconds?: number;
495
+ constructor(message: string, status: number, requestId?: string, code?: string, retryAfterSeconds?: number);
490
496
  }
491
497
  /** HTTP 502. */
492
498
  declare class UpstreamError extends AnyAPIError {
package/dist/index.js CHANGED
@@ -33,6 +33,13 @@ var NotFoundError = class extends AnyAPIError {
33
33
  var ResultNotFoundError = class extends NotFoundError {
34
34
  };
35
35
  var RateLimitedError = class extends AnyAPIError {
36
+ retryAfterSeconds;
37
+ constructor(message, status, requestId, code, retryAfterSeconds) {
38
+ super(message, status, requestId, code);
39
+ if (retryAfterSeconds !== void 0) {
40
+ this.retryAfterSeconds = retryAfterSeconds;
41
+ }
42
+ }
36
43
  };
37
44
  var UpstreamError = class extends AnyAPIError {
38
45
  };
@@ -55,7 +62,7 @@ function requestIdOf(headers) {
55
62
  }
56
63
  return void 0;
57
64
  }
58
- function errorFromStatus(status, message, requestId, code) {
65
+ function errorFromStatus(status, message, requestId, code, retryAfterSeconds) {
59
66
  switch (status) {
60
67
  case 400:
61
68
  return new BadRequestError(message, status, requestId, code);
@@ -66,7 +73,7 @@ function errorFromStatus(status, message, requestId, code) {
66
73
  case 404:
67
74
  return new NotFoundError(message, status, requestId, code);
68
75
  case 429:
69
- return new RateLimitedError(message, status, requestId, code);
76
+ return new RateLimitedError(message, status, requestId, code, retryAfterSeconds);
70
77
  case 502:
71
78
  return new UpstreamError(message, status, requestId, code);
72
79
  default:
@@ -897,9 +904,8 @@ var AnyAPI = class {
897
904
  const retryAfterMs = parseRetryAfterMs(
898
905
  response.headers.get("retry-after")
899
906
  );
900
- if (response.status === 429 && attempt < opts.maxRetries) {
901
- const delay = retryAfterMs !== void 0 ? Math.min(retryAfterMs, RETRY_MAX_DELAY_MS) : backoffDelay(attempt);
902
- await sleep(delay, opts.signal);
907
+ if (response.status === 429 && attempt < opts.maxRetries && (retryAfterMs === void 0 || retryAfterMs <= RETRY_MAX_DELAY_MS)) {
908
+ await sleep(retryAfterMs ?? backoffDelay(attempt), opts.signal);
903
909
  attempt += 1;
904
910
  continue;
905
911
  }
@@ -912,7 +918,13 @@ var AnyAPI = class {
912
918
  continue;
913
919
  }
914
920
  }
915
- throw errorFromStatus(response.status, message, requestId, code);
921
+ throw errorFromStatus(
922
+ response.status,
923
+ message,
924
+ requestId,
925
+ code,
926
+ retryAfterMs === void 0 ? void 0 : Math.ceil(retryAfterMs / 1e3)
927
+ );
916
928
  }
917
929
  }
918
930
  /** Internal accessor for GET helpers in account.ts (same base URL / machinery). */