2 namespace Mogic\Extname\Controller;
\r
4 use TYPO3\CMS\Core\Error\Http\PageNotFoundException;
\r
5 use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
\r
8 * Controller base class that catches exceptions and displays them nicely
\r
10 * @author Christian Weiske <weiske@mogic.com>
\r
12 abstract class AbstractExceptionHandlingController extends ActionController
\r
15 * Message to show when an element is not found (404)
\r
18 protected $notFoundMessage = 'Element not found';
\r
21 * Message to show when an unknown error occurs (e.g. API exception)
\r
24 protected $genericErrorMessage = 'Es ist ein schwerer Fehler aufgetreten.';
\r
28 * We currently do not need this.
\r
30 * Handles a request.
\r
31 * The result output is returned by altering the given response.
\r
33 * @param object $request The request object
\r
34 * @param object $response The response, modified by this handler
\r
38 public function DEACTprocessRequest(
\r
39 \TYPO3\CMS\Extbase\Mvc\RequestInterface $request,
\r
40 \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response
\r
43 parent::processRequest($request, $response);
\r
44 } catch (PageNotFoundException $e) {
\r
45 $this->handleNotFoundError($e);
\r
46 } catch (\Exception $e) {
\r
47 $this->handleGenericError($e);
\r
52 * Call the correct action method
\r
56 public function callActionMethod()
\r
59 parent::callActionMethod();
\r
60 } catch (PageNotFoundException $e) {
\r
61 $this->handleNotFoundError($e);
\r
62 } catch (\Exception $e) {
\r
63 $this->handleGenericError($e);
\r
68 * Handle a "element not found"-exception
\r
70 * @param object $exception Exception
\r
74 public function handleNotFoundError(\Exception $e)
\r
76 //$GLOBALS['TSFE']->pageNotFoundAndExit($this->notFoundMessage);
\r
78 'typo3conf/ext/extname/Resources/Private/Templates/Error/NotFound.html',
\r
79 $this->notFoundMessage,
\r
82 $this->response->setStatus(404);
\r
86 * Handle a generic undetermined error
\r
88 * @param object $exception Exception
\r
92 public function handleGenericError(\Exception $e)
\r
95 $GLOBALS['TSFE']->pageUnavailableAndExit(
\r
96 $this->genericErrorMessage,
\r
97 'HTTP/1.1 500 Internal Server Error'
\r
100 $this->renderError(
\r
101 'typo3conf/ext/extname/Resources/Private/Templates/Error/Generic.html',
\r
102 $this->genericErrorMessage,
\r
105 $this->response->setStatus(500);
\r
109 * Render an error message into a template
\r
111 * @param string $templateFile Template path
\r
112 * @param string $message Error message
\r
113 * @param object $e Exception that caused this error message
\r
117 protected function renderError($templateFile, $message, \Exception $e)
\r
119 $this->view->setTemplatePathAndFilename($templateFile);
\r
120 $this->view->assign('error', $message);
\r
121 $this->view->assign('exception', $e);
\r
122 $this->response->setContent($this->view->render());
\r