fix: restore native arm64 architecture support in Dockerfile and improve API error handling
This commit is contained in:
@@ -125,8 +125,22 @@ export function useHospitalStore() {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: data ? JSON.stringify(data) : undefined,
|
||||
});
|
||||
if (!res.ok) throw new Error(`API error: ${res.statusText}`);
|
||||
return await res.json().catch(() => ({ ok: true }));
|
||||
if (!res.ok) {
|
||||
let errText = res.statusText;
|
||||
try {
|
||||
const errData = await res.json();
|
||||
if (errData && errData.error) errText = errData.error;
|
||||
} catch {
|
||||
// ignore json parse error
|
||||
}
|
||||
throw new Error(`API error: ${errText}`);
|
||||
}
|
||||
const text = await res.text();
|
||||
try {
|
||||
return JSON.parse(text);
|
||||
} catch {
|
||||
return { ok: true };
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(`API call failed: ${method} ${endpoint}`, err);
|
||||
throw err;
|
||||
|
||||
@@ -41,8 +41,10 @@ export function GestionUsuarios() {
|
||||
const fetchUsuarios = async () => {
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/usuarios`);
|
||||
const data = await res.json();
|
||||
setUsuarios(data);
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
if (Array.isArray(data)) setUsuarios(data);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
} finally {
|
||||
@@ -53,8 +55,10 @@ export function GestionUsuarios() {
|
||||
const fetchGrupos = async () => {
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/grupos`);
|
||||
const data = await res.json();
|
||||
setGrupos(data);
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
if (Array.isArray(data)) setGrupos(data);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user