【发布时间】:2020-11-30 09:57:12
【问题描述】:
有谁知道在 Laravel 中限制特定异常的电子邮件通知的方法?
当出现数据库错误时,我通过检查QueryException 让我的应用程序向我发送了一封电子邮件。这是我在 Laravel 的异常处理程序中所做的一个粗略示例:
class Handler{
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exception
* @return void
*/
public function report(Exception $e)
{
if($e instanceof QueryException){
if( App::environment(['production']) ){
Notification::route('mail', 'myemail@test.com')
->notify(new DbErrorNotification($e));
}
}
parent::report($e);
}
}
在 DB 中缺少跟踪,有没有办法可以按异常类型限制 DB 错误,这样如果出现一致的 DB 错误,我最终不会收到数千封电子邮件。
我查看了Swift Mailer's anti-flood and throttling 插件,但它们会影响全局系统,我不想这样做。
提前谢谢你
【问题讨论】:
-
一种方法是肯定的会话。
标签: php database laravel email swiftmailer