From c150df3dc2fb4a370453d53639f131066636448b Mon Sep 17 00:00:00 2001 From: Ichsanix Date: Fri, 12 Jun 2026 21:26:30 +0700 Subject: [PATCH] fourth commit --- config/helpers.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/config/helpers.php b/config/helpers.php index 0ae6f43..2aa48c1 100644 --- a/config/helpers.php +++ b/config/helpers.php @@ -3,6 +3,22 @@ // config/helpers.php — Shared utility functions // ============================================================ +/** + * Global exception handler to return JSON on fatal errors. + */ +set_exception_handler(function(Throwable $e) { + header('Content-Type: application/json; charset=utf-8'); + header('Access-Control-Allow-Origin: *'); + http_response_code(500); + echo json_encode([ + 'error' => 'Internal Server Error', + 'message' => $e->getMessage(), + 'file' => basename($e->getFile()), + 'line' => $e->getLine() + ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); + exit; +}); + /** * Set JSON response headers and output data. */