From 37a198f3309ba228be89c98bcb7d4adc504122f3 Mon Sep 17 00:00:00 2001 From: Collina Systems Date: Mon, 6 Jul 2026 15:16:05 -0600 Subject: [PATCH] =?UTF-8?q?Fix:=20aprobar/baja/rechazar=20de=20becarios=20?= =?UTF-8?q?devolv=C3=ADan=20400=20(body=20vac=C3=ADo=20+=20Content-Type=20?= =?UTF-8?q?JSON)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit apiFetch declaraba Content-Type: application/json en TODA petición; Fastify rechaza un cuerpo vacío con ese header (FST_ERR_CTP_EMPTY_JSON_BODY → 400), lo que rompía todos los POST administrativos sin cuerpo: aprobar becario, baja y rechazar solicitud (y logout, cuyo error se tragaba el catch). No es una regresión del rediseño —la llamada y el helper son byte-idénticos a main—; es un defecto latente del helper compartido que Fastify rechaza. Ahora apiFetch sólo pone Content-Type JSON cuando de verdad hay body. Las peticiones con cuerpo (login, PATCH becario/jornada, ajustes, config, autorizar, cerrar) no cambian. No se tocó ningún endpoint, campo ni la lógica de bitácora. Verificado: aprobar Demo Pendiente pendiente→activo (200) y escribe bitácora; baja y rechazar también 200 + bitácora; las peticiones con body siguen 201/200. --- frontend/panel.html | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/frontend/panel.html b/frontend/panel.html index a2f5ad6..1926458 100644 --- a/frontend/panel.html +++ b/frontend/panel.html @@ -31,11 +31,12 @@ const { useState, useEffect, useCallback } = React; // ═══════════════════════════════════════════════════════════ const API_BASE = `${window.location.origin}/api`; async function apiFetch(path, options = {}) { - const res = await fetch(`${API_BASE}${path}`, { - credentials: "include", - ...options, - headers: { "Content-Type": "application/json", ...(options.headers || {}) }, - }); + // Content-Type JSON SOLO cuando hay body: Fastify rechaza un cuerpo vacío con + // application/json (FST_ERR_CTP_EMPTY_JSON_BODY → 400), lo que rompía todos los + // POST sin cuerpo (aprobar/baja/rechazar/logout). Con body, el header se pone. + const headers = { ...(options.headers || {}) }; + if (options.body != null) headers["Content-Type"] = "application/json"; + const res = await fetch(`${API_BASE}${path}`, { credentials: "include", ...options, headers }); const data = await res.json().catch(() => ({})); if (!res.ok) { const err = new Error(data.error || `HTTP ${res.status}`);