Fix: aprobar/baja/rechazar de becarios devolvían 400 (body vacío + Content-Type JSON)

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.
This commit is contained in:
Collina Systems committed 2026-07-06 15:16:05 -06:00
1 parent ae27ed6e69
commit 37a198f330
1 file changed
+6 -5
+6 -5
View File
@@ -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}`);