|
1 | | -<?php namespace SQLgreyGUI\Exceptions; |
| 1 | +<?php |
| 2 | + |
| 3 | +namespace SQLgreyGUI\Exceptions; |
2 | 4 |
|
3 | 5 | use Exception; |
| 6 | +use Illuminate\Database\Eloquent\ModelNotFoundException; |
| 7 | +use Symfony\Component\HttpKernel\Exception\HttpException; |
| 8 | +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
4 | 9 | use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; |
5 | 10 |
|
6 | | -class Handler extends ExceptionHandler { |
7 | | - |
8 | | - /** |
9 | | - * A list of the exception types that should not be reported. |
10 | | - * |
11 | | - * @var array |
12 | | - */ |
13 | | - protected $dontReport = [ |
14 | | - 'Symfony\Component\HttpKernel\Exception\HttpException' |
15 | | - ]; |
| 11 | +class Handler extends ExceptionHandler |
| 12 | +{ |
| 13 | + /** |
| 14 | + * A list of the exception types that should not be reported. |
| 15 | + * |
| 16 | + * @var array |
| 17 | + */ |
| 18 | + protected $dontReport = [ |
| 19 | + HttpException::class, |
| 20 | + ModelNotFoundException::class, |
| 21 | + ]; |
16 | 22 |
|
17 | | - /** |
18 | | - * Report or log an exception. |
19 | | - * |
20 | | - * This is a great spot to send exceptions to Sentry, Bugsnag, etc. |
21 | | - * |
22 | | - * @param \Exception $e |
23 | | - * @return void |
24 | | - */ |
25 | | - public function report(Exception $e) |
26 | | - { |
27 | | - return parent::report($e); |
28 | | - } |
| 23 | + /** |
| 24 | + * Report or log an exception. |
| 25 | + * |
| 26 | + * This is a great spot to send exceptions to Sentry, Bugsnag, etc. |
| 27 | + * |
| 28 | + * @param \Exception $e |
| 29 | + */ |
| 30 | + public function report(Exception $e) |
| 31 | + { |
| 32 | + return parent::report($e); |
| 33 | + } |
29 | 34 |
|
30 | | - /** |
31 | | - * Render an exception into an HTTP response. |
32 | | - * |
33 | | - * @param \Illuminate\Http\Request $request |
34 | | - * @param \Exception $e |
35 | | - * @return \Illuminate\Http\Response |
36 | | - */ |
37 | | - public function render($request, Exception $e) |
38 | | - { |
39 | | - return parent::render($request, $e); |
40 | | - } |
| 35 | + /** |
| 36 | + * Render an exception into an HTTP response. |
| 37 | + * |
| 38 | + * @param \Illuminate\Http\Request $request |
| 39 | + * @param \Exception $e |
| 40 | + * |
| 41 | + * @return \Illuminate\Http\Response |
| 42 | + */ |
| 43 | + public function render($request, Exception $e) |
| 44 | + { |
| 45 | + if ($e instanceof ModelNotFoundException) { |
| 46 | + $e = new NotFoundHttpException($e->getMessage(), $e); |
| 47 | + } |
41 | 48 |
|
| 49 | + return parent::render($request, $e); |
| 50 | + } |
42 | 51 | } |
0 commit comments