‪TYPO3CMS  10.4
ProductionExceptionHandler.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Psr\Log\LoggerAwareInterface;
19 use Psr\Log\LoggerAwareTrait;
24 
29 class ‪ProductionExceptionHandler implements ‪ExceptionHandlerInterface, LoggerAwareInterface
30 {
31  use LoggerAwareTrait;
32 
36  protected ‪$configuration = [];
37 
41  public function ‪__construct(array ‪$configuration = [])
42  {
43  $this->configuration = ‪$configuration;
44  }
45 
57  public function ‪handle(\‪Exception $exception, ‪AbstractContentObject $contentObject = null, $contentObjectConfiguration = [])
58  {
59  // ImmediateResponseException should work similar to exit / die and must therefore not be handled by this ExceptionHandler.
60  if ($exception instanceof ‪ImmediateResponseException) {
61  throw $exception;
62  }
63 
64  if (!empty($this->configuration['ignoreCodes.'])) {
65  if (in_array($exception->getCode(), array_map('intval', $this->configuration['ignoreCodes.']), true)) {
66  throw $exception;
67  }
68  }
69  $errorMessage = $this->configuration['errorMessage'] ?? 'Oops, an error occurred! Code: %s';
70  $code = date('YmdHis', $_SERVER['REQUEST_TIME']) . GeneralUtility::makeInstance(Random::class)->generateRandomHexString(8);
71 
72  $this->‪logException($exception, $errorMessage, $code);
73 
74  return sprintf($errorMessage, $code);
75  }
76 
82  protected function ‪logException(\‪Exception $exception, $errorMessage, $code)
83  {
84  $this->logger->alert(sprintf($errorMessage, $code), ['exception' => $exception]);
85  }
86 }
‪TYPO3\CMS\Frontend\ContentObject\Exception\ProductionExceptionHandler\__construct
‪__construct(array $configuration=[])
Definition: ProductionExceptionHandler.php:40
‪TYPO3\CMS\Frontend\ContentObject\Exception\ExceptionHandlerInterface
Definition: ExceptionHandlerInterface.php:24
‪TYPO3\CMS\Frontend\ContentObject\Exception
Definition: ContentRenderingException.php:16
‪TYPO3\CMS\Frontend\ContentObject\Exception\ProductionExceptionHandler\handle
‪string handle(\Exception $exception, AbstractContentObject $contentObject=null, $contentObjectConfiguration=[])
Definition: ProductionExceptionHandler.php:56
‪TYPO3\CMS\Frontend\ContentObject\Exception\ProductionExceptionHandler\logException
‪logException(\Exception $exception, $errorMessage, $code)
Definition: ProductionExceptionHandler.php:81
‪TYPO3\CMS\Frontend\ContentObject\Exception\ProductionExceptionHandler\$configuration
‪array $configuration
Definition: ProductionExceptionHandler.php:35
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject
Definition: AbstractContentObject.php:25
‪TYPO3\CMS\Core\Error\Exception
Definition: Exception.php:22
‪TYPO3\CMS\Core\Crypto\Random
Definition: Random.php:24
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Http\ImmediateResponseException
Definition: ImmediateResponseException.php:30
‪TYPO3\CMS\Frontend\ContentObject\Exception\ProductionExceptionHandler
Definition: ProductionExceptionHandler.php:30