silverstripe-cms/code/Controllers/ErrorPageControllerExtension.php
2017-01-31 13:59:35 +13:00

35 lines
859 B
PHP

<?php
namespace SilverStripe\CMS\Controllers;
use SilverStripe\CMS\Model\ErrorPage;
use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Core\Extension;
/**
* Enhances error handling for a controller with ErrorPage generated output
*/
class ErrorPageControllerExtension extends Extension
{
/**
* Used by {@see RequestHandler::httpError}
*
* @param int $statusCode
* @param HTTPRequest $request
* @throws HTTPResponse_Exception
*/
public function onBeforeHTTPError($statusCode, $request)
{
if (Director::is_ajax()) {
return;
}
$response = ErrorPage::response_for($statusCode);
if ($response) {
throw new HTTPResponse_Exception($response, $statusCode);
}
}
}