@ethlete/query 4.0.0 → 4.0.1

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.
@@ -49,6 +49,25 @@ const queryStateDoesNotContainKeyError = (data) => new QueryError('005', 'The qu
49
49
  const queryStateCannotTransformError = (data) => new QueryError('006', 'The query state cannot be transformed because it is not loading', data);
50
50
  const invalidBodyError = (data) => new QueryError('007', 'The body is not valid or upsupported', data);
51
51
 
52
+ const isSymfonyError = (error) => {
53
+ if (!error || typeof error !== 'object') {
54
+ return false;
55
+ }
56
+ const symfonyError = error;
57
+ return (symfonyError.class !== undefined &&
58
+ symfonyError.detail !== undefined &&
59
+ symfonyError.status !== undefined &&
60
+ symfonyError.title !== undefined &&
61
+ symfonyError.trace !== undefined &&
62
+ symfonyError.type !== undefined);
63
+ };
64
+ const isSymfonyPagerfantaOutOfRangeError = (error) => {
65
+ if (!isSymfonyError(error)) {
66
+ return false;
67
+ }
68
+ return error.class.startsWith('Pagerfanta') && error.class.endsWith('OutOfRangeCurrentPageException');
69
+ };
70
+
52
71
  const isRequestError = (error) => error instanceof Object && 'status' in error && 'statusText' in error && 'url' in error;
53
72
  const buildRoute = (options) => {
54
73
  if (options.base.endsWith('/')) {
@@ -279,9 +298,13 @@ const shouldRetryRequest = (config) => {
279
298
  if (!isRequestError(config.error)) {
280
299
  return { retry: false };
281
300
  }
282
- const { status } = config.error;
301
+ const { status, detail } = config.error;
283
302
  // Retry on 5xx errors
284
303
  if (status >= 500) {
304
+ // Don't retry if a requested page is out of range
305
+ if (isSymfonyPagerfantaOutOfRangeError(detail)) {
306
+ return { retry: false };
307
+ }
285
308
  return { retry: true, delay: defaultRetryDelay };
286
309
  }
287
310
  // Retry on 408 or 425 errors
@@ -506,25 +529,6 @@ const gql = (strings, ...values) => {
506
529
  return str;
507
530
  };
508
531
 
509
- const isSymfonyError = (error) => {
510
- if (!error || typeof error !== 'object') {
511
- return false;
512
- }
513
- const symfonyError = error;
514
- return (symfonyError.class !== undefined &&
515
- symfonyError.detail !== undefined &&
516
- symfonyError.status !== undefined &&
517
- symfonyError.title !== undefined &&
518
- symfonyError.trace !== undefined &&
519
- symfonyError.type !== undefined);
520
- };
521
- const isSymfonyPagerfantaOutOfRangeError = (error) => {
522
- if (!isSymfonyError(error)) {
523
- return false;
524
- }
525
- return error.class.startsWith('Pagerfanta') && error.class.endsWith('OutOfRangeCurrentPageException');
526
- };
527
-
528
532
  /* eslint-disable @typescript-eslint/no-explicit-any */
529
533
  function filterSuccess() {
530
534
  return function (source) {