mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
API Error page support for Security controller errors
This commit is contained in:
parent
fcb6a9140c
commit
f9cb8805e1
@ -1,3 +1,6 @@
|
||||
LeftAndMain:
|
||||
extensions:
|
||||
- LeftAndMainPageIconsExtension
|
||||
Security:
|
||||
extensions:
|
||||
- ErrorPageControllerExtension
|
||||
|
17
code/controllers/ErrorPageControllerExtension.php
Normal file
17
code/controllers/ErrorPageControllerExtension.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Enhances error handling for a controller with ErrorPage generated output
|
||||
*
|
||||
* @package cms
|
||||
* @subpackage controller
|
||||
*/
|
||||
class ErrorPageControllerExtension extends Extension {
|
||||
|
||||
public function onBeforeHTTPError($statusCode, $request) {
|
||||
$response = ErrorPage::response_for($statusCode);
|
||||
if($response) {
|
||||
throw new SS_HTTPResponse_Exception($response, $statusCode);
|
||||
}
|
||||
}
|
||||
}
|
@ -70,4 +70,16 @@ class ErrorPageTest extends FunctionalTest {
|
||||
$this->assertEquals($response->getStatusCode(), '403');
|
||||
$this->assertNotNull($response->getBody(), 'We have body text from the error page');
|
||||
}
|
||||
|
||||
public function testSecurityError() {
|
||||
// Generate 404 page
|
||||
$page = $this->objFromFixture('ErrorPage', '404');
|
||||
$page->publish('Stage', 'Live');
|
||||
|
||||
// Test invalid action
|
||||
$response = $this->get('Security/nosuchaction');
|
||||
$this->assertEquals($response->getStatusCode(), '404');
|
||||
$this->assertNotNull($response->getBody());
|
||||
$this->assertContains('text/html', $response->getHeader('Content-Type'));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user