LoginSignup
1
0

More than 3 years have passed since last update.

エラーレポートしない例外を動的に判定する

Posted at

問題

  1. カスタムExceptionHandlerを使ってエラーレポートを収集している
  2. アプリケーションで独自に定義しているExceptionを使ってエラーレスポンスを構築する仕組みが存在する
  3. (2) と衝突してしまうため $dontReport に無視する例外を追加していた
  4. (3) の数が多くなってきたので名前空間でマッチさせて無視したくなった

解決法

shouldReport(Exception $e) をオーバーライドして get_class() の戻り値で判定した。

public function shouldReport(Exception $e)
{
    $className = get_class($e);
    $knownError = Str::startsWith($className, 'App\Exceptions');
    if ($knownError) {
        return false;
    }

    return parent::shouldReport($e);
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0