/**
  *	Display an error page on invalid request.
  *
  *	@parameter <{ERROR_CODE}> integer
  *	@parameter <{ERROR_MESSAGE}> string
  */
 public function httpError($code, $message = null)
 {
     // Determine the error page for the given status code.
     $errorPages = ErrorPage::get()->filter('ErrorCode', $code);
     // Allow extension customisation.
     $this->extend('updateErrorPages', $errorPages);
     // Retrieve the error page response.
     if ($errorPage = $errorPages->first()) {
         Requirements::clear();
         Requirements::clear_combined_files();
         $response = ModelAsController::controller_for($errorPage)->handleRequest(new SS_HTTPRequest('GET', ''), DataModel::inst());
         throw new SS_HTTPResponse_Exception($response, $code);
     } else {
         if (file_exists($cachedPage = ErrorPage::get_filepath_for_errorcode($code, class_exists('Translatable') ? Translatable::get_current_locale() : null))) {
             $response = new SS_HTTPResponse();
             $response->setStatusCode($code);
             $response->setBody(file_get_contents($cachedPage));
             throw new SS_HTTPResponse_Exception($response, $code);
         } else {
             return parent::httpError($code, $message);
         }
     }
 }
 /**
  * @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);
     }
 }
 /**
  * @uses ErrorPage::response_for()
  */
 public function httpError($code, $message = null)
 {
     // Don't use the HTML response for media requests
     $response = $this->getRequest()->isMedia() ? null : ErrorPage::response_for($code);
     // Failover to $message if the HTML response is unavailable / inappropriate
     parent::httpError($code, $response ? $response : $message);
 }
 /**
  * @param Controller $controller
  *
  * @throws SS_HTTPResponse_Exception
  */
 public function respondNoAccess(Controller $controller)
 {
     $response = null;
     if (class_exists('ErrorPage', true)) {
         $response = ErrorPage::response_for(403);
     }
     $controller->httpError(403, $response ? $response : 'The requested page could not be found.');
 }
 /**
  * Return a HTTP error to the user
  */
 public function httpError($errorCode = 404, $errorMessage = null)
 {
     $template = array('Error', 'BaseController');
     $result = new ArrayData(array('Title' => 'Whoops!', 'Content' => DBField::create_field('HTMLText', $errorMessage)));
     parent::httpError($errorCode, new SS_HTTPResponse($result->renderWith($template)));
 }
 /**
  * Handles rendering of the preview for an object
  * @return {string} Response to send to the object
  */
 public function preview()
 {
     $auth = $this->request->getVar('auth');
     $token = KapostPreviewToken::get()->filter('Code', Convert::raw2sql($auth))->first();
     //Verify the token exists and hasn't expired yet
     if (!empty($token) && $token !== false && $token->exists() && time() - strtotime($token->Created) < self::config()->preview_token_expiry * 60 && $token->KapostRefID == $this->urlParams['ID']) {
         $kapostObj = KapostObject::get()->filter('KapostRefID', Convert::raw2sql($this->urlParams['ID']))->sort('"Created" DESC')->first();
         if (!empty($kapostObj) && $kapostObj !== false && $kapostObj->exists()) {
             $previewController = $kapostObj->renderPreview();
             $this->extend('updatePreviewDisplay', $kapostObj, $previewController);
             return $previewController;
         }
     }
     //Token expired or object not found
     if (class_exists('ErrorPage')) {
         $response = ErrorPage::response_for(404);
         if (!empty($response)) {
             return $response;
         }
     }
     return parent::httpError(404);
 }