TYPO3 CMS  TYPO3_7-6
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 
21 
26 {
30  protected $configuration = [];
31 
35  public function __construct(array $configuration = [])
36  {
37  $this->configuration = $configuration;
38  }
39 
51  public function handle(\Exception $exception, AbstractContentObject $contentObject = null, $contentObjectConfiguration = [])
52  {
53  if (!empty($this->configuration['ignoreCodes.'])) {
54  if (in_array($exception->getCode(), array_map('intval', $this->configuration['ignoreCodes.']), true)) {
55  throw $exception;
56  }
57  }
58  $errorMessage = isset($this->configuration['errorMessage']) ? $this->configuration['errorMessage'] : 'Oops, an error occurred! Code: %s';
59  $code = date('YmdHis', $_SERVER['REQUEST_TIME']) . GeneralUtility::getRandomHexString(8);
60 
61  $this->logException($exception, $errorMessage, $code);
62 
63  return sprintf($errorMessage, $code);
64  }
65 
71  protected function logException(\Exception $exception, $errorMessage, $code)
72  {
73  $this->getLogger()->alert(sprintf($errorMessage, $code), ['exception' => $exception]);
74  }
75 
79  protected function getLogger()
80  {
81  return GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
82  }
83 }
handle(\Exception $exception, AbstractContentObject $contentObject=null, $contentObjectConfiguration=[])