TYPO3 CMS  TYPO3_8-7
ProductionExceptionHandler.php
Go to the documentation of this file.
1 <?php
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  */
16 
22 
27 {
31  protected $configuration = [];
32 
36  public function __construct(array $configuration = [])
37  {
38  $this->configuration = $configuration;
39  }
40 
52  public function handle(\Exception $exception, AbstractContentObject $contentObject = null, $contentObjectConfiguration = [])
53  {
54  if (!empty($this->configuration['ignoreCodes.'])) {
55  if (in_array($exception->getCode(), array_map('intval', $this->configuration['ignoreCodes.']), true)) {
56  throw $exception;
57  }
58  }
59  $errorMessage = isset($this->configuration['errorMessage']) ? $this->configuration['errorMessage'] : 'Oops, an error occurred! Code: %s';
60  $code = date('YmdHis', $_SERVER['REQUEST_TIME']) . GeneralUtility::makeInstance(Random::class)->generateRandomHexString(8);
61 
62  $this->logException($exception, $errorMessage, $code);
63 
64  return sprintf($errorMessage, $code);
65  }
66 
72  protected function logException(\Exception $exception, $errorMessage, $code)
73  {
74  $this->getLogger()->alert(sprintf($errorMessage, $code), ['exception' => $exception]);
75  }
76 
80  protected function getLogger()
81  {
82  return GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
83  }
84 }
static makeInstance($className,... $constructorArguments)
handle(\Exception $exception, AbstractContentObject $contentObject=null, $contentObjectConfiguration=[])