silverstripe-cms/code/Controllers/ErrorPageControllerExtension.php

35 lines
859 B
PHP
Raw Normal View History

<?php
2016-07-22 01:32:32 +02:00
namespace SilverStripe\CMS\Controllers;
use SilverStripe\CMS\Model\ErrorPage;
use SilverStripe\Control\Director;
2016-09-09 01:26:24 +02:00
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Core\Extension;
2016-07-22 01:32:32 +02:00
/**
* Enhances error handling for a controller with ErrorPage generated output
*/
2017-01-25 21:59:25 +01:00
class ErrorPageControllerExtension extends Extension
{
2015-09-29 06:18:03 +02:00
2017-01-25 21:59:25 +01:00
/**
* 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);
}
}
}