TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
core/Classes/Error/ProductionExceptionHandler.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Error;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
19 
26 {
32  protected $defaultTitle = 'Oops, an error occurred!';
33 
39  protected $defaultMessage = '';
40 
44  public function __construct()
45  {
46  set_exception_handler([$this, 'handleException']);
47  }
48 
55  public function echoExceptionWeb(\Throwable $exception)
56  {
57  $this->sendStatusHeaders($exception);
58  $this->writeLogEntries($exception, self::CONTEXT_WEB);
59  echo GeneralUtility::makeInstance(ErrorPageController::class)->errorAction(
60  $this->getTitle($exception),
61  $this->getMessage($exception),
63  $this->discloseExceptionInformation($exception) ? $exception->getCode() : 0
64  );
65  }
66 
73  public function echoExceptionCLI(\Throwable $exception)
74  {
75  $filePathAndName = $exception->getFile();
76  $exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : '';
77  $this->writeLogEntries($exception, self::CONTEXT_CLI);
78  echo LF . 'Uncaught TYPO3 Exception ' . $exceptionCodeNumber . $exception->getMessage() . LF;
79  echo 'thrown in file ' . $filePathAndName . LF;
80  echo 'in line ' . $exception->getLine() . LF . LF;
81  die(1);
82  }
83 
90  protected function discloseExceptionInformation(\Throwable $exception)
91  {
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(\Throwable $exception)
117  {
118  if ($this->discloseExceptionInformation($exception) && method_exists($exception, 'getTitle') && $exception->getTitle() !== '') {
119  return $exception->getTitle();
120  } else {
121  return $this->defaultTitle;
122  }
123  }
124 
131  protected function getMessage(\Throwable $exception)
132  {
133  if ($this->discloseExceptionInformation($exception)) {
134  return $exception->getMessage();
135  } else {
136  return $this->defaultMessage;
137  }
138  }
139 }
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)