1 | <?php |
||
2 | |||
3 | namespace App\Exceptions; |
||
4 | |||
5 | use App\Mail\ExceptionOccured; |
||
6 | use Exception; |
||
7 | use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; |
||
8 | use Illuminate\Support\Facades\Log; |
||
9 | use Mail; |
||
10 | use Symfony\Component\Debug\Exception\FlattenException; |
||
11 | use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler; |
||
12 | |||
13 | class Handler extends ExceptionHandler |
||
14 | { |
||
15 | /** |
||
16 | * A list of the exception types that are not reported. |
||
17 | * |
||
18 | * @var array |
||
19 | */ |
||
20 | protected $dontReport = [ |
||
21 | // |
||
22 | ]; |
||
23 | |||
24 | /** |
||
25 | * A list of the inputs that are never flashed for validation exceptions. |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $dontFlash = [ |
||
30 | 'password', |
||
31 | 'password_confirmation', |
||
32 | ]; |
||
33 | |||
34 | /** |
||
35 | * Report or log an exception. |
||
36 | * |
||
37 | * This is a great spot to send exceptions to Sentry, Bugsnag, etc. |
||
38 | * |
||
39 | * @param \Exception $exception |
||
40 | * |
||
41 | * @return void |
||
42 | */ |
||
43 | public function report(Exception $exception) |
||
44 | { |
||
45 | $enableEmailExceptions = config('exceptions.emailExceptionEnabled'); |
||
46 | |||
47 | if ($enableEmailExceptions === '') { |
||
48 | $enableEmailExceptions = config('exceptions.emailExceptionEnabledDefault'); |
||
49 | } |
||
50 | |||
51 | if ($enableEmailExceptions && $this->shouldReport($exception)) { |
||
52 | $this->sendEmail($exception); |
||
53 | } |
||
54 | |||
55 | parent::report($exception); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Render an exception into an HTTP response. |
||
60 | * |
||
61 | * @param \Illuminate\Http\Request $request |
||
62 | * @param \Exception $exception |
||
63 | * |
||
64 | * @return \Illuminate\Http\Response |
||
65 | */ |
||
66 | public function render($request, Exception $exception) |
||
67 | { |
||
68 | return parent::render($request, $exception); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Sends an email upon exception. |
||
73 | * |
||
74 | * @param \Exception $exception |
||
75 | * |
||
76 | * @return void |
||
77 | */ |
||
78 | public function sendEmail(Exception $exception) |
||
79 | { |
||
80 | try { |
||
81 | $e = FlattenException::create($exception); |
||
82 | $handler = new SymfonyExceptionHandler(); |
||
0 ignored issues
–
show
Deprecated Code
introduced
by
![]() |
|||
83 | $html = $handler->getHtml($e); |
||
84 | |||
85 | Mail::send(new ExceptionOccured($html)); |
||
86 | } catch (Exception $exception) { |
||
87 | Log::error($exception); |
||
88 | } |
||
89 | } |
||
90 | } |
||
91 |