2014-05-02 02:52:18 +02:00
|
|
|
<?php
|
|
|
|
|
2016-07-22 01:32:32 +02:00
|
|
|
namespace SilverStripe\CMS\Controllers;
|
|
|
|
|
|
|
|
use SilverStripe\CMS\Model\ErrorPage;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\Control\Director;
|
2016-09-09 01:26:24 +02:00
|
|
|
use SilverStripe\Control\HTTPRequest;
|
|
|
|
use SilverStripe\Control\HTTPResponse_Exception;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\Core\Extension;
|
2016-07-22 01:32:32 +02:00
|
|
|
|
2014-05-02 02:52:18 +02:00
|
|
|
/**
|
|
|
|
* Enhances error handling for a controller with ErrorPage generated output
|
|
|
|
*/
|
|
|
|
class ErrorPageControllerExtension extends Extension {
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2016-01-26 06:38:42 +01:00
|
|
|
/**
|
|
|
|
* Used by {@see RequestHandler::httpError}
|
|
|
|
*
|
|
|
|
* @param int $statusCode
|
2016-09-09 01:26:24 +02:00
|
|
|
* @param HTTPRequest $request
|
|
|
|
* @throws HTTPResponse_Exception
|
2016-01-26 06:38:42 +01:00
|
|
|
*/
|
2014-05-02 02:52:18 +02:00
|
|
|
public function onBeforeHTTPError($statusCode, $request) {
|
2016-08-23 04:36:06 +02:00
|
|
|
if (Director::is_ajax()) {
|
2016-08-22 05:16:27 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-05-02 02:52:18 +02:00
|
|
|
$response = ErrorPage::response_for($statusCode);
|
|
|
|
if($response) {
|
2016-09-09 01:26:24 +02:00
|
|
|
throw new HTTPResponse_Exception($response, $statusCode);
|
2014-05-02 02:52:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|