1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Exceptions; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Illuminate\Validation\ValidationException; |
7
|
|
|
use Illuminate\Auth\Access\AuthorizationException; |
8
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException; |
9
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException; |
10
|
|
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; |
11
|
|
|
|
12
|
|
|
class Handler extends ExceptionHandler |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* A list of the exception types that should not be reported. |
16
|
|
|
* |
17
|
|
|
* @var array |
18
|
|
|
*/ |
19
|
|
|
protected $dontReport = [ |
20
|
|
|
AuthorizationException::class, |
21
|
|
|
HttpException::class, |
22
|
|
|
ModelNotFoundException::class, |
23
|
|
|
ValidationException::class, |
24
|
|
|
]; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Report or log an exception. |
28
|
|
|
* |
29
|
|
|
* This is a great spot to send exceptions to Sentry, Bugsnag, etc. |
30
|
|
|
* |
31
|
|
|
* @param \Exception $e |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
|
|
public function report(Exception $e) |
35
|
|
|
{ |
36
|
|
|
parent::report($e); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Render an exception into an HTTP response. |
41
|
|
|
* |
42
|
|
|
* @param \Illuminate\Http\Request $request |
43
|
|
|
* @param \Exception $e |
44
|
|
|
* @return \Illuminate\Http\Response |
45
|
|
|
*/ |
46
|
|
|
public function render($request, Exception $e) |
47
|
|
|
{ |
48
|
|
|
if ($this->isHttpException($e)) { |
49
|
|
|
if (config('app.debug')) { |
50
|
|
|
return $this->renderExceptionWithWhoops($e); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return $this->renderHttpException($e); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return parent::render($request, $e); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Render an exception using Whoops. |
61
|
|
|
* |
62
|
|
|
* @param \Exception $e |
63
|
|
|
* @return \Illuminate\Http\Response |
64
|
|
|
*/ |
65
|
|
|
protected function renderExceptionWithWhoops(Exception $e) |
66
|
|
|
{ |
67
|
|
|
$whoops = new \Whoops\Run; |
68
|
|
|
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler()); |
|
|
|
|
69
|
|
|
|
70
|
|
|
return new \Illuminate\Http\Response( |
71
|
|
|
$whoops->handleException($e), |
|
|
|
|
72
|
|
|
$e->getStatusCode(), |
|
|
|
|
73
|
|
|
$e->getHeaders() |
|
|
|
|
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.