Permalink
Browse files

FIX Use RequestHandler::httpError() for all HTTP errors.

silverstripe/silverstripe-framework#827 adds some extension points for catching HTTP errors such as 404.  This change fixes some issues where httpError() isn't used all the time.  Note that the aforementioned pull request will be necessary to ensure that it works properly.
  • Loading branch information...
1 parent 686f703 commit 39792debb8888237639d2b316181e685658894d8 @sminnee sminnee committed Sep 27, 2012
Showing with 6 additions and 10 deletions.
  1. +4 −5 code/controllers/ContentController.php
  2. +2 −5 code/controllers/ModelAsController.php
View
9 code/controllers/ContentController.php
@@ -205,11 +205,10 @@ public function handleRequest(SS_HTTPRequest $request, DataModel $model = null)
* @uses ErrorPage::response_for()
*/
public function httpError($code, $message = null) {
- if($this->request->isMedia() || !$response = ErrorPage::response_for($code)) {
- parent::httpError($code, $message);
- } else {
- throw new SS_HTTPResponse_Exception($response);
- }
+ // Don't use the HTML response for media requests
+ $response = $this->request->isMedia() ? null : ErrorPage::response_for($code);
+ // Failover to $message if the HTML response is unavailable / inappropriate
+ parent::httpError($code, $response ? $response : $message);
}
/**
View
7 code/controllers/ModelAsController.php
@@ -126,11 +126,8 @@ public function getNestedController() {
return $this->response;
}
- if($response = ErrorPage::response_for(404)) {
- return $response;
- } else {
- $this->httpError(404, 'The requested page could not be found.');
- }
+ $response = ErrorPage::response_for(404);
+ $this->httpError(404, $response ? $response : 'The requested page could not be found.');
}
// Enforce current locale setting to the loaded SiteTree object

0 comments on commit 39792de

Please sign in to comment.