@openmrs/esm-react-utils 8.0.1-pre.3529 → 8.0.1-pre.3537

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.
@@ -1,3 +1,3 @@
1
- [0] Successfully compiled: 52 files with swc (133.29ms)
1
+ [0] Successfully compiled: 52 files with swc (135.11ms)
2
2
  [0] swc --strip-leading-paths src -d dist exited with code 0
3
3
  [1] tsc --project tsconfig.build.json exited with code 0
@@ -14,7 +14,7 @@ function _define_property(obj, key, value) {
14
14
  import React, { Suspense } from "react";
15
15
  import { I18nextProvider } from "react-i18next";
16
16
  import { SWRConfig } from "swr";
17
- import { openmrsFetch } from "@openmrs/esm-api";
17
+ import { openmrsFetch, OpenmrsFetchError } from "@openmrs/esm-api";
18
18
  import { ComponentContext } from "./ComponentContext.js";
19
19
  const defaultOpts = {
20
20
  strictMode: true,
@@ -35,6 +35,22 @@ const defaultSwrConfig = {
35
35
  revalidateOnFocus: false,
36
36
  revalidateOnReconnect: false,
37
37
  refreshInterval: 0,
38
+ shouldRetryOnError: (error)=>{
39
+ if (error instanceof OpenmrsFetchError) {
40
+ const status = error.response.status;
41
+ // retry all server-side errors
42
+ if (status >= 500) {
43
+ return true;
44
+ }
45
+ // retry on authentication failure or rate-limited requests
46
+ if (status === 401 || status === 403 || status === 429) {
47
+ return true;
48
+ }
49
+ // do not retry on other client-side errors
50
+ return false;
51
+ }
52
+ return true;
53
+ },
38
54
  provider: ()=>swrCache
39
55
  };
40
56
  export function openmrsComponentDecorator(userOpts) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-react-utils",
3
- "version": "8.0.1-pre.3529",
3
+ "version": "8.0.1-pre.3537",
4
4
  "license": "MPL-2.0",
5
5
  "description": "React utilities for OpenMRS.",
6
6
  "type": "module",
@@ -79,17 +79,17 @@
79
79
  "swr": "2.x"
80
80
  },
81
81
  "devDependencies": {
82
- "@openmrs/esm-api": "8.0.1-pre.3529",
83
- "@openmrs/esm-config": "8.0.1-pre.3529",
84
- "@openmrs/esm-context": "8.0.1-pre.3529",
85
- "@openmrs/esm-emr-api": "8.0.1-pre.3529",
86
- "@openmrs/esm-error-handling": "8.0.1-pre.3529",
87
- "@openmrs/esm-extensions": "8.0.1-pre.3529",
88
- "@openmrs/esm-feature-flags": "8.0.1-pre.3529",
89
- "@openmrs/esm-globals": "8.0.1-pre.3529",
90
- "@openmrs/esm-navigation": "8.0.1-pre.3529",
91
- "@openmrs/esm-state": "8.0.1-pre.3529",
92
- "@openmrs/esm-utils": "8.0.1-pre.3529",
82
+ "@openmrs/esm-api": "8.0.1-pre.3537",
83
+ "@openmrs/esm-config": "8.0.1-pre.3537",
84
+ "@openmrs/esm-context": "8.0.1-pre.3537",
85
+ "@openmrs/esm-emr-api": "8.0.1-pre.3537",
86
+ "@openmrs/esm-error-handling": "8.0.1-pre.3537",
87
+ "@openmrs/esm-extensions": "8.0.1-pre.3537",
88
+ "@openmrs/esm-feature-flags": "8.0.1-pre.3537",
89
+ "@openmrs/esm-globals": "8.0.1-pre.3537",
90
+ "@openmrs/esm-navigation": "8.0.1-pre.3537",
91
+ "@openmrs/esm-state": "8.0.1-pre.3537",
92
+ "@openmrs/esm-utils": "8.0.1-pre.3537",
93
93
  "@swc/cli": "^0.7.7",
94
94
  "@swc/core": "^1.11.29",
95
95
  "@vitest/coverage-v8": "^4.0.7",
@@ -2,7 +2,7 @@ import React, { type ComponentType, type ErrorInfo, Suspense } from 'react';
2
2
  import { I18nextProvider } from 'react-i18next';
3
3
  import { type Cache, SWRConfig, type SWRConfiguration } from 'swr';
4
4
  import type {} from '@openmrs/esm-globals';
5
- import { openmrsFetch } from '@openmrs/esm-api';
5
+ import { openmrsFetch, OpenmrsFetchError } from '@openmrs/esm-api';
6
6
  import { type ComponentConfig, type ExtensionData } from '@openmrs/esm-extensions';
7
7
  import { ComponentContext } from './ComponentContext';
8
8
 
@@ -27,6 +27,25 @@ const defaultSwrConfig: SWRConfiguration = {
27
27
  revalidateOnFocus: false,
28
28
  revalidateOnReconnect: false,
29
29
  refreshInterval: 0,
30
+ shouldRetryOnError: (error) => {
31
+ if (error instanceof OpenmrsFetchError) {
32
+ const status = error.response.status;
33
+ // retry all server-side errors
34
+ if (status >= 500) {
35
+ return true;
36
+ }
37
+
38
+ // retry on authentication failure or rate-limited requests
39
+ if (status === 401 || status === 403 || status === 429) {
40
+ return true;
41
+ }
42
+
43
+ // do not retry on other client-side errors
44
+ return false;
45
+ }
46
+
47
+ return true;
48
+ },
30
49
  provider: () => swrCache,
31
50
  };
32
51