From ecda99626d50ccf00a132344eda74c82c1ac3df8 Mon Sep 17 00:00:00 2001 From: Peter Szalatnay Date: Sun, 8 Jun 2025 19:27:43 +0800 Subject: [PATCH 1/2] Update ExceptionHandler.php --- libraries/src/Exception/ExceptionHandler.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libraries/src/Exception/ExceptionHandler.php b/libraries/src/Exception/ExceptionHandler.php index 84aa52a7beefb..0ff5eae162d0f 100644 --- a/libraries/src/Exception/ExceptionHandler.php +++ b/libraries/src/Exception/ExceptionHandler.php @@ -87,11 +87,14 @@ public static function render(\Throwable $error) try { $app = Factory::getApplication(); - // Flag if we are on cli + // Flag if we are on cli or api $isCli = $app->isClient('cli'); + $isAPI = $app->isClient('api'); // If site is offline and it's a 404 error, just go to index (to see offline message, instead of 404) - if (!$isCli && $error->getCode() == '404' && $app->get('offline') == 1) { + if ($isCli || $isAPI) { + // Do nothing. + } elseif ($error->getCode() == '404' && $app->get('offline') == 1) { $app->redirect('index.php'); } @@ -141,6 +144,11 @@ public static function render(\Throwable $error) } if ($isCli) { + echo $data; + } elseif ($isAPI){ + $app->setHeader('Content-Type', $app->mimeType . '; charset=' . $app->charSet); + $app->sendHeaders(); + echo $data; } else { /** @var CMSApplication $app */ From 2559dbb8c4b74cc0082eea70b989bce9eb22694c Mon Sep 17 00:00:00 2001 From: Peter Szalatnay Date: Mon, 9 Jun 2025 17:02:38 +0800 Subject: [PATCH 2/2] Update libraries/src/Exception/ExceptionHandler.php Co-authored-by: Richard Fath --- libraries/src/Exception/ExceptionHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/Exception/ExceptionHandler.php b/libraries/src/Exception/ExceptionHandler.php index 0ff5eae162d0f..7fbe87fd4440c 100644 --- a/libraries/src/Exception/ExceptionHandler.php +++ b/libraries/src/Exception/ExceptionHandler.php @@ -145,7 +145,7 @@ public static function render(\Throwable $error) if ($isCli) { echo $data; - } elseif ($isAPI){ + } elseif ($isAPI) { $app->setHeader('Content-Type', $app->mimeType . '; charset=' . $app->charSet); $app->sendHeaders();