diff --git a/Classes/DebugExceptionHandler.php b/Classes/DebugExceptionHandler.php index 2c7f11e..883d10e 100644 --- a/Classes/DebugExceptionHandler.php +++ b/Classes/DebugExceptionHandler.php @@ -2,7 +2,10 @@ namespace Networkteam\SentryClient; +use Networkteam\SentryClient\Event\BeforeSentryCaptureEvent; use Networkteam\SentryClient\Service\SentryService; +use Psr\EventDispatcher\EventDispatcherInterface; +use TYPO3\CMS\Core\Utility\GeneralUtility; class DebugExceptionHandler extends \TYPO3\CMS\Core\Error\DebugExceptionHandler { @@ -18,7 +21,17 @@ public function __construct() */ public function handleException(\Throwable $exception): void { - Client::captureException($exception); + $eventDispatcher = GeneralUtility::makeInstance(EventDispatcherInterface::class); + + $event = $eventDispatcher->dispatch( + new BeforeSentryCaptureEvent($exception) + ); + + if (!$event->isPropagationStopped()) { + $exceptionToSend = $event->getException(); + Client::captureException($exceptionToSend); + } + parent::handleException($exception); } -} \ No newline at end of file +} diff --git a/Classes/Event/BeforeSentryCaptureEvent.php b/Classes/Event/BeforeSentryCaptureEvent.php new file mode 100644 index 0000000..52bc2b7 --- /dev/null +++ b/Classes/Event/BeforeSentryCaptureEvent.php @@ -0,0 +1,47 @@ +exception = $exception; + } + + public function getException(): Throwable + { + return $this->exception; + } + + public function setException(Throwable $exception): void + { + $this->exception = $exception; + } + + public function isPropagationStopped(): bool + { + return $this->propagationStopped; + } + + public function stopPropagation(): void + { + $this->propagationStopped = true; + } +} diff --git a/Classes/ProductionExceptionHandler.php b/Classes/ProductionExceptionHandler.php index 23146fe..7010a9c 100644 --- a/Classes/ProductionExceptionHandler.php +++ b/Classes/ProductionExceptionHandler.php @@ -2,9 +2,12 @@ namespace Networkteam\SentryClient; +use Networkteam\SentryClient\Event\BeforeSentryCaptureEvent; use Networkteam\SentryClient\Service\ConfigurationService; use Networkteam\SentryClient\Service\SentryService; +use Psr\EventDispatcher\EventDispatcherInterface; use Sentry\EventId; +use TYPO3\CMS\Core\Utility\GeneralUtility; class ProductionExceptionHandler extends \TYPO3\CMS\Core\Error\ProductionExceptionHandler { @@ -23,9 +26,20 @@ public function __construct() public function handleException(\Throwable $exception): void { $ignoredCodes = array_merge(self::IGNORED_EXCEPTION_CODES, self::IGNORED_HMAC_EXCEPTION_CODES); + if (!in_array($exception->getCode(), $ignoredCodes, true)) { - $this->eventId = Client::captureException($exception); + $eventDispatcher = GeneralUtility::makeInstance(EventDispatcherInterface::class); + + $event = $eventDispatcher->dispatch( + new BeforeSentryCaptureEvent($exception) + ); + + if (!$event->isPropagationStopped()) { + $exceptionToSend = $event->getException(); + $this->eventId = Client::captureException($exceptionToSend); + } } + parent::handleException($exception); } @@ -54,4 +68,4 @@ protected function writeLog(string $logMessage) parent::writeLog($logMessage); } -} \ No newline at end of file +} diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 98678c6..999e058 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -11,4 +11,4 @@ services: tags: - name: event.listener identifier: 'SentryStatus' - event: TYPO3\CMS\Backend\Backend\Event\SystemInformationToolbarCollectorEvent \ No newline at end of file + event: TYPO3\CMS\Backend\Backend\Event\SystemInformationToolbarCollectorEvent diff --git a/Resources/Public/JavaScript/remove-usercentrics-glitchtip-cookie.js b/Resources/Public/JavaScript/remove-usercentrics-glitchtip-cookie.js new file mode 100644 index 0000000..2ef2fda --- /dev/null +++ b/Resources/Public/JavaScript/remove-usercentrics-glitchtip-cookie.js @@ -0,0 +1,11 @@ +function removeCookieByName(name) { + const cookieName = name; + const pastDate = 'Thu, 01 Jan 1970 00:00:00 GMT'; + + document.cookie = `${cookieName}=; expires=${pastDate}; path=/; SameSite=Lax; Secure`; + + console.log(`Attempted to remove cookie "${cookieName}". Check browser developer tools to confirm.`); +} + +const cookieNameToRemove = 'allow-glitchtip'; +removeCookieByName(cookieNameToRemove); diff --git a/Resources/Public/JavaScript/set-usercentrics-glitchtip-cookie.js b/Resources/Public/JavaScript/set-usercentrics-glitchtip-cookie.js new file mode 100644 index 0000000..7a64178 --- /dev/null +++ b/Resources/Public/JavaScript/set-usercentrics-glitchtip-cookie.js @@ -0,0 +1,15 @@ +function setPersistentCookie(name, value, days) { + let expires = ""; + if (days) { + const date = new Date(); + date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); + expires = "; expires=" + date.toUTCString(); + } + document.cookie = name + "=" + (value || "") + expires + "; path=/; SameSite=Lax; Secure"; +} + +const cookieName = 'allow-glitchtip'; +const cookieValue = 'true'; +const expirationInDays = 365; + +setPersistentCookie(cookieName, cookieValue, expirationInDays);