1 | <?php |
||
2 | |||
3 | namespace App\Exceptions; |
||
4 | |||
5 | use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; |
||
6 | use Throwable; |
||
7 | |||
8 | class Handler extends ExceptionHandler |
||
9 | { |
||
10 | /** |
||
11 | * A list of the exception types that should not be reported. |
||
12 | * |
||
13 | * @var array |
||
14 | */ |
||
15 | protected $dontReport = [ |
||
16 | \Illuminate\Auth\AuthenticationException::class, |
||
17 | \Illuminate\Auth\Access\AuthorizationException::class, |
||
18 | \Symfony\Component\HttpKernel\Exception\HttpException::class, |
||
19 | \Illuminate\Database\Eloquent\ModelNotFoundException::class, |
||
20 | \Illuminate\Session\TokenMismatchException::class, |
||
21 | \Illuminate\Validation\ValidationException::class, |
||
22 | ]; |
||
23 | |||
24 | /** |
||
25 | * A list of the exceptions that can be upgraded. Checked in order. |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $upgradable = [ |
||
30 | \LibreNMS\Exceptions\FilePermissionsException::class, |
||
31 | \LibreNMS\Exceptions\DatabaseConnectException::class, |
||
32 | \LibreNMS\Exceptions\DuskUnsafeException::class, |
||
33 | \LibreNMS\Exceptions\UnserializableRouteCache::class, |
||
34 | \LibreNMS\Exceptions\MaximumExecutionTimeExceeded::class, |
||
35 | \LibreNMS\Exceptions\DatabaseInconsistentException::class, |
||
36 | ]; |
||
37 | |||
38 | public function render($request, Throwable $exception) |
||
39 | { |
||
40 | // If for some reason Blade hasn't been registered, try it now |
||
41 | try { |
||
42 | if (! app()->bound('view')) { |
||
43 | app()->register(\Illuminate\View\ViewServiceProvider::class); |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
44 | app()->register(\Illuminate\Translation\TranslationServiceProvider::class); |
||
45 | } |
||
46 | } catch (\Exception $e) { |
||
47 | // continue without view |
||
48 | } |
||
49 | |||
50 | // try to upgrade generic exceptions to more specific ones |
||
51 | if (! config('app.debug')) { |
||
52 | foreach ($this->upgradable as $class) { |
||
53 | if ($new = $class::upgrade($exception)) { |
||
54 | return parent::render($request, $new); |
||
55 | } |
||
56 | } |
||
57 | } |
||
58 | |||
59 | return parent::render($request, $exception); |
||
60 | } |
||
61 | |||
62 | protected function convertExceptionToArray(Throwable $e) |
||
63 | { |
||
64 | // override the non-debug error output to clue in user on how to debug |
||
65 | if (! config('app.debug') && ! $this->isHttpException($e)) { |
||
66 | return ['message' => 'Server Error: Set APP_DEBUG=true to see details.']; |
||
67 | } |
||
68 | |||
69 | return parent::convertExceptionToArray($e); |
||
70 | } |
||
71 | } |
||
72 |