TYPO3 CMS  TYPO3_6-2
ProductionExceptionHandler.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Error;
3 
25 
31  protected $defaultTitle = 'Oops, an error occurred!';
32 
38  protected $defaultMessage = '';
39 
45  public function __construct() {
46  set_exception_handler(array($this, 'handleException'));
47  }
48 
55  public function echoExceptionWeb(\Exception $exception) {
56  $this->sendStatusHeaders($exception);
57  $this->writeLogEntries($exception, self::CONTEXT_WEB);
59  'TYPO3\\CMS\\Core\\Messaging\\ErrorpageMessage',
60  $this->getMessage($exception),
61  $this->getTitle($exception)
62  );
63  $messageObj->output();
64  }
65 
72  public function echoExceptionCLI(\Exception $exception) {
73  $filePathAndName = $exception->getFile();
74  $exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : '';
75  $this->writeLogEntries($exception, self::CONTEXT_CLI);
76  echo '
77 Uncaught TYPO3 Exception ' . $exceptionCodeNumber . $exception->getMessage() . LF;
78  echo 'thrown in file ' . $filePathAndName . LF;
79  echo 'in line ' . $exception->getLine() . '
80 
81 ';
82  die(1);
83  }
84 
91  protected function discloseExceptionInformation(\Exception $exception) {
92  // Allow message to be shown in production mode if the exception is about
93  // trusted host configuration. By doing so we do not disclose
94  // any valuable information to an attacker but avoid confusions among TYPO3 admins
95  // in production context.
96  if ($exception->getCode() === 1396795884) {
97  return TRUE;
98  }
99  // Show client error messages 40x in every case
100  if ($exception instanceof Http\AbstractClientErrorException) {
101  return TRUE;
102  }
103  // Only show errors in FE, if a BE user is authenticated
104  if (TYPO3_MODE === 'FE') {
105  return $GLOBALS['TSFE']->beUserLogin;
106  }
107  return TRUE;
108  }
109 
116  protected function getTitle(\Exception $exception) {
117  if ($this->discloseExceptionInformation($exception) && method_exists($exception, 'getTitle') && $exception->getTitle() !== '') {
118  return htmlspecialchars($exception->getTitle());
119  } else {
120  return $this->defaultTitle;
121  }
122  }
123 
130  protected function getMessage(\Exception $exception) {
131  if ($this->discloseExceptionInformation($exception)) {
132  // Exception has an error code given
133  if ($exception->getCode() > 0) {
134  $moreInformationLink = '<p>More information regarding this error might be available <a href="'
135  . TYPO3_URL_EXCEPTION . $exception->getCode() . '" target="_blank">online</a>.</p>';
136  } else {
137  $moreInformationLink = '';
138  }
139  return htmlspecialchars($exception->getMessage()) . $moreInformationLink;
140  } else {
141  return $this->defaultMessage;
142  }
143  }
144 
145 }
const TYPO3_MODE
Definition: init.php:40
die
Definition: index.php:6
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]