@zauru-sdk/hooks 2.0.121 → 2.0.122
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/esm/catalogs.js +25 -25
- package/package.json +2 -2
package/dist/esm/catalogs.js
CHANGED
|
@@ -64,17 +64,22 @@ function useGetReduxCatalog(CATALOG_NAME, { online = false, wheres = [], otherPa
|
|
|
64
64
|
fetcher.load(`/api/catalogs?catalog=${CATALOG_NAME}${queryString}`);
|
|
65
65
|
}
|
|
66
66
|
catch (error) {
|
|
67
|
-
console.error(error);
|
|
68
67
|
// Si hay datos locales, mostramos los datos locales
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
68
|
+
if (hasLocalData) {
|
|
69
|
+
console.error("Hubo un error pero hay datos locales en la consulta de", CATALOG_NAME, " Error: ", error);
|
|
70
|
+
setData({
|
|
71
|
+
data: catalogData?.data || [],
|
|
72
|
+
loading: false,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
console.error("Hubo un error y no hay datos locales en la consulta de", CATALOG_NAME, " Error: ", error);
|
|
77
|
+
(0, index_js_1.showAlert)({
|
|
78
|
+
type: "error",
|
|
79
|
+
title: "Error al cargar el catálogo",
|
|
80
|
+
description: `Error al cargar el catálogo ${CATALOG_NAME}, por favor intente nuevamente. Error: ${error}`,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
78
83
|
}
|
|
79
84
|
}
|
|
80
85
|
else {
|
|
@@ -98,30 +103,22 @@ function useGetReduxCatalog(CATALOG_NAME, { online = false, wheres = [], otherPa
|
|
|
98
103
|
if (fetcher.data) {
|
|
99
104
|
const possibleError = fetcher.data;
|
|
100
105
|
const possibleData = fetcher.data;
|
|
101
|
-
// Si es un error "clásico"
|
|
102
|
-
if (possibleError?.
|
|
103
|
-
// Aquí interpretamos que la API pudo haber respondido algo tipo { description, ... } => error
|
|
106
|
+
// Si es un error "clásico", lo manejamos
|
|
107
|
+
if (possibleError?.error) {
|
|
104
108
|
// Pero OJO: si ya teníamos datos locales, no mostramos error "fatal" para no romper el fallback
|
|
105
109
|
if (hasLocalData) {
|
|
106
|
-
|
|
107
|
-
// pero no borramos lo que hay en data
|
|
108
|
-
(0, index_js_1.showAlert)({
|
|
109
|
-
type: possibleError.type || "error",
|
|
110
|
-
title: possibleError.title || "Error",
|
|
111
|
-
description: possibleError.description,
|
|
112
|
-
});
|
|
113
|
-
// Marcamos loading false pero dejamos intacto `data.data`
|
|
114
|
-
setData((prev) => ({ ...prev, loading: false }));
|
|
110
|
+
console.log("Hay error en la respuesta pero hay datos locales en la consulta de", CATALOG_NAME);
|
|
115
111
|
}
|
|
116
112
|
else {
|
|
113
|
+
console.log("Hay error en la respuesta y no hay datos locales en la consulta de", CATALOG_NAME);
|
|
117
114
|
// No hay datos locales -> mostramos error y no tenemos fallback
|
|
118
115
|
(0, index_js_1.showAlert)({
|
|
119
116
|
type: "error",
|
|
120
117
|
title: possibleError.title || "Error",
|
|
121
118
|
description: possibleError.description,
|
|
122
119
|
});
|
|
123
|
-
setData((prev) => ({ ...prev, loading: false }));
|
|
124
120
|
}
|
|
121
|
+
setData((prev) => ({ ...prev, loading: false }));
|
|
125
122
|
}
|
|
126
123
|
else {
|
|
127
124
|
// Caso: la respuesta sí es data real
|
|
@@ -141,6 +138,7 @@ function useGetReduxCatalog(CATALOG_NAME, { online = false, wheres = [], otherPa
|
|
|
141
138
|
// Por alguna razón no llegó el array esperado
|
|
142
139
|
// Revisamos si hay fallback local
|
|
143
140
|
if (hasLocalData) {
|
|
141
|
+
console.log("Hubo un error en el parseo de la respuesta pero hay datos locales en la consulta de", CATALOG_NAME, " retornó: ", newData);
|
|
144
142
|
// No reportar error: usamos lo local
|
|
145
143
|
setData((prev) => ({ ...prev, loading: false }));
|
|
146
144
|
}
|
|
@@ -151,6 +149,7 @@ function useGetReduxCatalog(CATALOG_NAME, { online = false, wheres = [], otherPa
|
|
|
151
149
|
title: "Error al recibir el catálogo",
|
|
152
150
|
description: `No se obtuvo la propiedad "${CATALOG_NAME}" en la respuesta.`,
|
|
153
151
|
});
|
|
152
|
+
console.log("Hubo un error en parseo de la respuesta y no hay datos locales en la consulta de", CATALOG_NAME, " retornó: ", newData);
|
|
154
153
|
setData((prev) => ({ ...prev, loading: false }));
|
|
155
154
|
}
|
|
156
155
|
}
|
|
@@ -160,17 +159,18 @@ function useGetReduxCatalog(CATALOG_NAME, { online = false, wheres = [], otherPa
|
|
|
160
159
|
// fetcher.state === "idle" pero fetcher.data es null/undefined => seguramente hubo error global
|
|
161
160
|
if (hasLocalData) {
|
|
162
161
|
// Fallback a datos locales
|
|
163
|
-
|
|
162
|
+
console.log("No hay datos en la respuesta pero hay datos locales en la consulta de", CATALOG_NAME);
|
|
164
163
|
}
|
|
165
164
|
else {
|
|
166
165
|
// Ni API ni local data => error
|
|
166
|
+
console.log("No hay datos en la respuesta y no hay datos locales en la consulta de", CATALOG_NAME);
|
|
167
167
|
(0, index_js_1.showAlert)({
|
|
168
168
|
type: "error",
|
|
169
169
|
title: "Error al cargar el catálogo",
|
|
170
170
|
description: `No se obtuvo respuesta y no hay datos locales para ${CATALOG_NAME}`,
|
|
171
171
|
});
|
|
172
|
-
setData((prev) => ({ ...prev, loading: false }));
|
|
173
172
|
}
|
|
173
|
+
setData((prev) => ({ ...prev, loading: false }));
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/hooks",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.122",
|
|
4
4
|
"description": "Hooks reutilizables dentro de las webapps de Zauru.",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"react": "^18.2.0",
|
|
34
34
|
"react-dom": "^18.2.0"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "3fec09bd29ced6f895b20e729d358448e3883f79"
|
|
37
37
|
}
|