Skip to content

Commit 0e85d4c

Browse files
committed
verify error context is not empty
1 parent 7909e3a commit 0e85d4c

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/Listeners/NotifyAdminOfError.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
use Hugomyb\ErrorMailer\Notifications\ErrorOccurred;
8+
use Illuminate\Support\Facades\Cache;
89
use Illuminate\Support\Facades\Config;
910
use Illuminate\Support\Facades\Mail;
1011

@@ -28,14 +29,23 @@ public function __construct()
2829
*/
2930
public function handle($event)
3031
{
31-
if (!in_array(env('APP_ENV'), config('error-mailer.disabledOn')) ) {
32-
if (config()->has('error-mailer.email.recipient')) {
33-
$recipient = config('error-mailer.email.recipient');
34-
} else {
35-
$recipient = '[email protected]';
36-
}
32+
if (!in_array(env('APP_ENV'), config('error-mailer.disabledOn'))) {
33+
34+
$recipient = config()->has('error-mailer.email.recipient')
35+
? config('error-mailer.email.recipient')
36+
37+
38+
$errorHash = md5($event->context['exception']->getMessage() . $event->context['exception']->getFile());
3739

38-
Mail::to($recipient)->send(new ErrorOccurred($event->context['exception']));
40+
$cacheKey = 'error_mailer_' . $errorHash;
41+
$coolDownPeriod = 15;
42+
43+
if (!Cache::has($cacheKey)) {
44+
if (isset($event->context['exception'])) {
45+
Mail::to($recipient)->send(new ErrorOccurred($event->context['exception']));
46+
Cache::put($cacheKey, true, now()->addMinutes($coolDownPeriod));
47+
}
48+
}
3949
}
4050
}
4151
}

0 commit comments

Comments
 (0)