Skip to content

Commit b95522e

Browse files
Fix error reporting level bug
1 parent 61d7e2c commit b95522e

2 files changed

Lines changed: 23 additions & 8 deletions

File tree

src/Flare.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,15 @@ public function report(Throwable $throwable, callable $callback = null)
207207

208208
protected function shouldSendReport(Throwable $throwable): bool
209209
{
210-
if ($this->throwableIsAnError($throwable) && $this->reportErrorLevels) {
210+
if($this->reportErrorLevels && $throwable instanceof Error){
211211
return $this->reportErrorLevels & $throwable->getCode();
212212
}
213213

214-
if ($this->filterExceptionsCallable) {
214+
if($this->reportErrorLevels && $throwable instanceof ErrorException){
215+
return $this->reportErrorLevels & $throwable->getSeverity();
216+
}
217+
218+
if ($this->filterExceptionsCallable && $throwable instanceof Exception) {
215219
return call_user_func($this->filterExceptionsCallable, $throwable);
216220
}
217221

@@ -310,10 +314,4 @@ protected function applyMiddlewareToReport(Report $report): Report
310314

311315
return $report;
312316
}
313-
314-
315-
protected function throwableIsAnError(Throwable $throwable): bool
316-
{
317-
return $throwable instanceof ErrorException || $throwable instanceof Error;
318-
}
319317
}

tests/FlareTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Facade\FlareClient\Tests;
44

55
use Error;
6+
use ErrorException;
67
use Facade\FlareClient\Api;
78
use Facade\FlareClient\Enums\MessageLevels;
89
use Facade\FlareClient\Flare;
@@ -354,4 +355,20 @@ public function it_can_filter_errors_based_on_their_level()
354355

355356
$this->fakeClient->assertRequestsSent(3);
356357
}
358+
359+
/** @test */
360+
public function it_can_filter_error_exceptions_based_on_their_severity()
361+
{
362+
$this->flare->report(new ErrorException('test', 0, E_NOTICE));
363+
$this->flare->report(new ErrorException('test', 0, E_WARNING));
364+
365+
$this->fakeClient->assertRequestsSent(2);
366+
367+
$this->flare->reportErrorLevels(E_ALL & ~E_NOTICE);
368+
369+
$this->flare->report(new ErrorException('test', 0, E_NOTICE));
370+
$this->flare->report(new ErrorException('test', 0, E_WARNING));
371+
372+
$this->fakeClient->assertRequestsSent(3);
373+
}
357374
}

0 commit comments

Comments
 (0)