Skip to content

Commit 5b82c0e

Browse files
authored
[5.3] Infinite API loop if site is offline and requesting unknow resource (joomla#45576)
1 parent a7659dd commit 5b82c0e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

libraries/src/Exception/ExceptionHandler.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,14 @@ public static function render(\Throwable $error)
8787
try {
8888
$app = Factory::getApplication();
8989

90-
// Flag if we are on cli
90+
// Flag if we are on cli or api
9191
$isCli = $app->isClient('cli');
92+
$isAPI = $app->isClient('api');
9293

9394
// If site is offline and it's a 404 error, just go to index (to see offline message, instead of 404)
94-
if (!$isCli && $error->getCode() == '404' && $app->get('offline') == 1) {
95+
if ($isCli || $isAPI) {
96+
// Do nothing.
97+
} elseif ($error->getCode() == '404' && $app->get('offline') == 1) {
9598
$app->redirect('index.php');
9699
}
97100

@@ -141,6 +144,11 @@ public static function render(\Throwable $error)
141144
}
142145

143146
if ($isCli) {
147+
echo $data;
148+
} elseif ($isAPI) {
149+
$app->setHeader('Content-Type', $app->mimeType . '; charset=' . $app->charSet);
150+
$app->sendHeaders();
151+
144152
echo $data;
145153
} else {
146154
/** @var CMSApplication $app */

0 commit comments

Comments
 (0)