Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #48 from karim-elshendy/ignore_ips
Browse files Browse the repository at this point in the history
#47 Ignore IPs for http exceptions
  • Loading branch information
benji07 committed Oct 9, 2015
2 parents 0c48ce4 + 01828a8 commit 1a06387
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public function getConfigTreeBuilder()
->end()
->treatNullLike(array())
->end()
->arrayNode('ignoredIPs')
->prototype('scalar')
->end()
->treatNullLike(array())
->end()
->end();

return $treeBuilder;
Expand Down
6 changes: 6 additions & 0 deletions Listener/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Notifier
private $reportErrors = false;
private $reportSilent = false;
private $repeatTimeout = false;
private $ignoredIPs;
private $command;
private $commandInput;

Expand Down Expand Up @@ -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);
Expand All @@ -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());
}
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 1a06387

Please sign in to comment.