1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PHPHub\Exceptions; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException; |
7
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException; |
8
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
9
|
|
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; |
10
|
|
|
use Whoops\Handler\JsonResponseHandler; |
11
|
|
|
use Whoops\Handler\PrettyPageHandler; |
12
|
|
|
use Whoops\Run as Whoops; |
13
|
|
|
|
14
|
|
|
class Handler extends ExceptionHandler |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* A list of the exception types that should not be reported. |
18
|
|
|
* |
19
|
|
|
* @var array |
20
|
|
|
*/ |
21
|
|
|
protected $dontReport = [ |
22
|
|
|
HttpException::class, |
23
|
|
|
ModelNotFoundException::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
|
|
|
*/ |
33
|
|
|
public function report(Exception $e) |
34
|
|
|
{ |
35
|
|
|
return parent::report($e); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Render an exception into an HTTP response. |
40
|
|
|
* |
41
|
|
|
* @param \Illuminate\Http\Request $request |
42
|
|
|
* @param \Exception $e |
43
|
|
|
* |
44
|
|
|
* @return \Illuminate\Http\Response |
45
|
|
|
*/ |
46
|
|
|
public function render($request, Exception $e) |
47
|
|
|
{ |
48
|
|
|
if ($e instanceof ModelNotFoundException) { |
49
|
|
|
$e = new NotFoundHttpException($e->getMessage(), $e); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if (config('app.debug')) { |
53
|
|
|
$whoops = new Whoops(); |
54
|
|
|
|
55
|
|
|
if ($request->ajax() || str_contains($request->header('Accept'), 'json')) { |
|
|
|
|
56
|
|
|
$whoops->pushHandler(new JsonResponseHandler()); |
|
|
|
|
57
|
|
|
} else { |
58
|
|
|
$whoops->pushHandler(new PrettyPageHandler()); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return response($whoops->handleException($e), |
62
|
|
|
$e->getStatusCode(), |
63
|
|
|
$e->getHeaders() |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return parent::render($request, $e); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.