From a00e44e730c62e995b422bf9c14871b6f40022d1 Mon Sep 17 00:00:00 2001 From: lizandrogd <77708265+lizandrogd@users.noreply.github.com> Date: Wed, 21 Jan 2026 13:48:25 -0500 Subject: [PATCH] Update media-url.php --- api/version/media-url.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/api/version/media-url.php b/api/version/media-url.php index 5cf8126..db3b280 100644 --- a/api/version/media-url.php +++ b/api/version/media-url.php @@ -20,6 +20,30 @@ function media_log($msg) { $resolvedFromGraph = false; $decoded = null; +// Log de petición inicial +media_log("Request: " . ($_SERVER['REQUEST_METHOD'] ?? 'GET') . " " . ($_SERVER['REQUEST_URI'] ?? '') . " GET:" . json_encode($_GET) . " POST:" . json_encode($_POST)); + +// Manejador de excepciones no capturadas -> devolver JSON claro +set_exception_handler(function($e){ + media_log("Uncaught exception: " . $e->getMessage() . " in " . $e->getFile() . ":" . $e->getLine()); + http_response_code(500); + header('Content-Type: application/json; charset=utf-8'); + echo json_encode(['success'=>false,'error'=>'Uncaught exception','detail'=>$e->getMessage()]); + exit; +}); + +// Shutdown handler para capturar errores fatales (E_ERROR, E_PARSE, ...) +register_shutdown_function(function(){ + $err = error_get_last(); + if ($err && in_array($err['type'], [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR])) { + media_log("Fatal error: " . ($err['message'] ?? '') . " in " . ($err['file'] ?? '') . ":" . ($err['line'] ?? '')); + http_response_code(500); + header('Content-Type: application/json; charset=utf-8'); + echo json_encode(['success'=>false,'error'=>'Fatal error','detail'=>$err]); + // no exit; (shutdown) + } +}); + $isGet = $_SERVER['REQUEST_METHOD'] === 'GET'; $accept = $_SERVER['HTTP_ACCEPT'] ?? ''; $wantsJson = strpos($accept, 'application/json') !== false;