scrapebadger 0.24.0 → 0.24.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.
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@ import { EventEmitter } from 'events';
3
3
  import WebSocket from 'ws';
4
4
 
5
5
  // src/internal/version.ts
6
- var SDK_VERSION = "0.24.0";
6
+ var SDK_VERSION = "0.24.2";
7
7
 
8
8
  // src/internal/exceptions.ts
9
9
  var ScrapeBadgerError = class _ScrapeBadgerError extends Error {
@@ -118,7 +118,8 @@ var WebSocketStreamError = class _WebSocketStreamError extends ScrapeBadgerError
118
118
  };
119
119
 
120
120
  // src/internal/client.ts
121
- var BaseClient = class {
121
+ var RETRYABLE_STATUS_CODES = [500, 502, 503, 504];
122
+ var BaseClient = class _BaseClient {
122
123
  config;
123
124
  constructor(config) {
124
125
  this.config = config;
@@ -178,7 +179,7 @@ var BaseClient = class {
178
179
  return { data, rateLimit };
179
180
  } catch (error) {
180
181
  lastError = error;
181
- if (error instanceof ScrapeBadgerError && !(error instanceof RateLimitError)) {
182
+ if (!_BaseClient.isRetryable(error)) {
182
183
  throw error;
183
184
  }
184
185
  if (attempt === this.config.maxRetries) {
@@ -305,6 +306,22 @@ var BaseClient = class {
305
306
  throw new ScrapeBadgerError(message);
306
307
  }
307
308
  }
309
+ /**
310
+ * Whether a failed request is worth another attempt.
311
+ *
312
+ * Retryable: transient server failures (500/502/503/504), request timeouts,
313
+ * rate limits, and raw network faults thrown by `fetch` itself. Everything
314
+ * else — auth, validation, not-found, conflict — is final.
315
+ */
316
+ static isRetryable(error) {
317
+ if (error instanceof ServerError) {
318
+ return RETRYABLE_STATUS_CODES.includes(error.statusCode);
319
+ }
320
+ if (error instanceof RateLimitError || error instanceof TimeoutError) {
321
+ return true;
322
+ }
323
+ return !(error instanceof ScrapeBadgerError);
324
+ }
308
325
  /**
309
326
  * Sleep for a given duration.
310
327
  */