Skip to content

Commit

Permalink
feat: filter every handled exceptions through a blacklist filter
Browse files Browse the repository at this point in the history
  • Loading branch information
cngJo committed Oct 4, 2022
1 parent 4302367 commit 4972040
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Classes/Handler/DebugExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions Classes/Handler/ProductionExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
26 changes: 26 additions & 0 deletions Classes/Service/Blacklist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Jops\TYPO3\Sentry\Service;

use Jops\TYPO3\Sentry\Domain\Configuration\Configuration;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class Blacklist
{
/**
* Check weather the given string gets matched by the configured blacklist regex.
* If the blacklist regex is empty, this will always return false.
*/
public static function isExcluded(string $className): bool
{
$configuration = GeneralUtility::makeInstance(Configuration::class);
$pattern = $configuration->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;
}
}

0 comments on commit 4972040

Please sign in to comment.