From 4972040a20f2155d4e144f702bc102b404dc840c Mon Sep 17 00:00:00 2001 From: Johannes Przymusinski Date: Mon, 3 Oct 2022 23:06:25 +0200 Subject: [PATCH] feat: filter every handled exceptions through a blacklist filter --- Classes/Handler/DebugExceptionHandler.php | 7 +++++ .../Handler/ProductionExceptionHandler.php | 6 +++++ Classes/Service/Blacklist.php | 26 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 Classes/Service/Blacklist.php diff --git a/Classes/Handler/DebugExceptionHandler.php b/Classes/Handler/DebugExceptionHandler.php index 7fd2e64..2187baf 100644 --- a/Classes/Handler/DebugExceptionHandler.php +++ b/Classes/Handler/DebugExceptionHandler.php @@ -3,6 +3,7 @@ namespace Jops\TYPO3\Sentry\Handler; use Jops\TYPO3\Sentry\Domain\Configuration\Configuration; +use Jops\TYPO3\Sentry\Service\Blacklist; use Jops\TYPO3\Sentry\Service\SentryService; use Throwable; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -15,6 +16,12 @@ public function handleException(Throwable $exception): void { $configuration = GeneralUtility::makeInstance(Configuration::class); + // Check weather the exception is excluded + if (Blacklist::isExcluded(get_class($exception))) { + parent::handleException($exception); + return; + } + $dsn = $configuration->getDsn(); if ($dsn === '' || $dsn === '0') { parent::handleException($exception); diff --git a/Classes/Handler/ProductionExceptionHandler.php b/Classes/Handler/ProductionExceptionHandler.php index 67c0add..f704c70 100644 --- a/Classes/Handler/ProductionExceptionHandler.php +++ b/Classes/Handler/ProductionExceptionHandler.php @@ -3,6 +3,7 @@ namespace Jops\TYPO3\Sentry\Handler; use Jops\TYPO3\Sentry\Domain\Configuration\Configuration; +use Jops\TYPO3\Sentry\Service\Blacklist; use Jops\TYPO3\Sentry\Service\SentryService; use Throwable; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -15,6 +16,11 @@ public function handleException(Throwable $exception): void { $configuration = GeneralUtility::makeInstance(Configuration::class); + // Check weather the exception is excluded + if (Blacklist::isExcluded(get_class($exception))) { + return; + } + $dsn = $configuration->getDsn(); if ($dsn === '' || $dsn === '0') { parent::handleException($exception); diff --git a/Classes/Service/Blacklist.php b/Classes/Service/Blacklist.php new file mode 100644 index 0000000..674cf07 --- /dev/null +++ b/Classes/Service/Blacklist.php @@ -0,0 +1,26 @@ +getBlacklistPattern(); + + // When the pattern is empty (not set), nothing should be excluded, so we just return false. + if ($pattern === "") { + return false; + } + + return preg_match($pattern, $className) > 0; + } +}