Skip to content
Snippets Groups Projects
Commit 71a121a9 authored by Demian Katz's avatar Demian Katz
Browse files

Merge pull request #458 from EreMaijala/system-status

Improved the SystemStatus AJAX call to also set HTTP status codes acc…
parents 064615d2 d94504af
Branches
Tags
No related merge requests found
...@@ -512,17 +512,22 @@ class AjaxController extends AbstractBase ...@@ -512,17 +512,22 @@ class AjaxController extends AbstractBase
/** /**
* Send output data and exit. * Send output data and exit.
* *
* @param mixed $data The response data * @param mixed $data The response data
* @param string $status Status of the request * @param string $status Status of the request
* @param int $httpCode A custom HTTP Status Code
* *
* @return \Zend\Http\Response * @return \Zend\Http\Response
* @throws \Exception
*/ */
protected function output($data, $status) protected function output($data, $status, $httpCode = null)
{ {
$response = $this->getResponse(); $response = $this->getResponse();
$headers = $response->getHeaders(); $headers = $response->getHeaders();
$headers->addHeaderLine('Cache-Control', 'no-cache, must-revalidate'); $headers->addHeaderLine('Cache-Control', 'no-cache, must-revalidate');
$headers->addHeaderLine('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT'); $headers->addHeaderLine('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT');
if ($httpCode !== null) {
$response->setStatusCode($httpCode);
}
if ($this->outputMode == 'json') { if ($this->outputMode == 'json') {
$headers->addHeaderLine('Content-type', 'application/javascript'); $headers->addHeaderLine('Content-type', 'application/javascript');
$output = ['data' => $data, 'status' => $status]; $output = ['data' => $data, 'status' => $status];
...@@ -1306,7 +1311,9 @@ class AjaxController extends AbstractBase ...@@ -1306,7 +1311,9 @@ class AjaxController extends AbstractBase
if (!empty($config->System->healthCheckFile) if (!empty($config->System->healthCheckFile)
&& file_exists($config->System->healthCheckFile) && file_exists($config->System->healthCheckFile)
) { ) {
return $this->output('Health check file exists', self::STATUS_ERROR); return $this->output(
'Health check file exists', self::STATUS_ERROR, 503
);
} }
// Test search index // Test search index
...@@ -1317,7 +1324,7 @@ class AjaxController extends AbstractBase ...@@ -1317,7 +1324,7 @@ class AjaxController extends AbstractBase
$results->performAndProcessSearch(); $results->performAndProcessSearch();
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->output( return $this->output(
'Search index error: ' . $e->getMessage(), self::STATUS_ERROR 'Search index error: ' . $e->getMessage(), self::STATUS_ERROR, 500
); );
} }
...@@ -1327,7 +1334,7 @@ class AjaxController extends AbstractBase ...@@ -1327,7 +1334,7 @@ class AjaxController extends AbstractBase
$sessionTable->getBySessionId('healthcheck', false); $sessionTable->getBySessionId('healthcheck', false);
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->output( return $this->output(
'Database error: ' . $e->getMessage(), self::STATUS_ERROR 'Database error: ' . $e->getMessage(), self::STATUS_ERROR, 500
); );
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment