Skip to content

Instantly share code, notes, and snippets.

@ogrosko
Created June 1, 2016 14:24
Show Gist options
  • Save ogrosko/7de0cb81033c8dc77a66f9248b8ceefd to your computer and use it in GitHub Desktop.
Save ogrosko/7de0cb81033c8dc77a66f9248b8ceefd to your computer and use it in GitHub Desktop.
Typo3 Plugin exception custom handling
<?php
namespace BinaryBay\BbBoilerplate\ContentObject\Exception;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\HttpUtility;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
use TYPO3\CMS\Frontend\ContentObject\AbstractContentObject;
class ProductionExceptionHandler extends \TYPO3\CMS\Frontend\ContentObject\Exception\ProductionExceptionHandler {
/**
* array
*/
protected $configuration = array();
/**
* array $configuration
*/
public function __construct(array $configuration = array()) {
parent::__construct($configuration);
}
/**
* Handles exceptions thrown during rendering of content objects
* The handler can decide whether to re-throw the exception or
* return a nice error message for production context.
*
* \Exception $exception
* AbstractContentObject $contentObject
* array $contentObjectConfiguration
* string
* \Exception
*/
public function handle(\Exception $exception, AbstractContentObject $contentObject = null, $contentObjectConfiguration = array()) {
if ( GeneralUtility::getApplicationContext() == 'Production' ) {
if (in_array($contentObjectConfiguration['extensionName'], $this->configuration['extensions.'])) {
$errors = array(1297759968, 1, 1298012500);
if (in_array($exception->getCode(), $errors)) {
$this->logException($exception, $exception->getMessage(), date('YmdHis', $_SERVER['REQUEST_TIME']) . GeneralUtility::getRandomHexString(8));
$GLOBALS['TSFE']->pageNotFoundAndExit($exception->getMessage(), HttpUtility::HTTP_STATUS_404);
}
}
else {
return parent::handle($exception, $contentObject, $contentObjectConfiguration);
}
}
else {
throw $exception;
}
}
}
config {
contentObjectExceptionHandler = BinaryBay\BbBoilerplate\ContentObject\Exception\ProductionExceptionHandler
contentObjectExceptionHandler.extensions {
10 = BbEvents
20 = BbPress
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment