diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 63eccc7..7f15a30 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -71,6 +71,11 @@ public function getConfigTreeBuilder() ->end() ->treatNullLike(array()) ->end() + ->arrayNode('ignoredIPs') + ->prototype('scalar') + ->end() + ->treatNullLike(array()) + ->end() ->end(); return $treeBuilder; diff --git a/Listener/Notifier.php b/Listener/Notifier.php index d63eb07..0b72c4f 100644 --- a/Listener/Notifier.php +++ b/Listener/Notifier.php @@ -46,6 +46,7 @@ class Notifier private $reportErrors = false; private $reportSilent = false; private $repeatTimeout = false; + private $ignoredIPs; private $command; private $commandInput; @@ -74,6 +75,7 @@ public function __construct(Swift_Mailer $mailer, EngineInterface $templating, $ $this->ignoredPhpErrors = $config['ignoredPhpErrors']; $this->repeatTimeout = $config['repeatTimeout']; $this->errorsDir = $cacheDir.'/errors'; + $this->ignoredIPs = $config['ignoredIPs']; if (!is_dir($this->errorsDir)) { mkdir($this->errorsDir); @@ -94,6 +96,10 @@ public function onKernelException(GetResponseForExceptionEvent $event) $exception = $event->getException(); if ($exception instanceof HttpException) { + if (in_array($event->getRequest()->getClientIp(), $this->ignoredIPs)) { + return; + } + if (500 === $exception->getStatusCode() || (404 === $exception->getStatusCode() && true === $this->handle404) || (in_array($exception->getStatusCode(), $this->handleHTTPcodes))) { $this->createMailAndSend($exception, $event->getRequest()); } diff --git a/README.md b/README.md index 124e2ec..bae9f03 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,17 @@ You may control the depth of recursion with a parameter, say foo = array('a'=>ar Default value is 1. (MAX_DEPTH const) +### How to ignore sending HTTP errors if request comes from given IPs ? + +If you want to ignore sending HTTP errors if the request comes from specific IPs, you can now specify the list of ignored IPs. + +```yml +# app/config/config_prod.yml +elao_error_notifier: + ignoredIPs: + - "178.63.45.100" + - ... +``` ## Screenshot