Skip to content

Commit

Permalink
Fix: Set failover object
Browse files Browse the repository at this point in the history
  • Loading branch information
jonom committed Jul 3, 2018
1 parent fb48139 commit ebbd817
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/CustomErrorControllerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ public function customError($errorCode, $customFields, $template = null, $contro
$defaultCustomFields,
$customFields
);
$body = $controllerType::create()->renderWith($template, $customFields);
// Remove 'Controller' from class name to get related Page type
$pageType = substr_replace($controllerType, '', strrpos($controllerType, 'Controller'), strlen('Controller'));
// Create a dummy page to act as a failover for the controller
$dataRecord = $pageType::create();
$dataRecord->ID = -1;
// Set the response body
$body = $controllerType::create($dataRecord)->renderWith($template, $customFields);
$response->setBody($body);
if ($response) {
throw new HTTPResponse_Exception($response, $errorCode);
Expand Down

0 comments on commit ebbd817

Please sign in to comment.