Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

75 lines
2.6 KiB
PHP
Raw Permalink Normal View History

2018-05-09 08:05:17 -05:00
<?php
namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
2020-07-09 15:22:50 +02:00
use Throwable;
2018-05-09 08:05:17 -05:00
class Handler extends ExceptionHandler
{
/**
2021-10-03 01:04:59 +02:00
* A list of the exception types that are not reported.
2018-05-09 08:05:17 -05:00
*/
protected $dontReport = [
\Illuminate\Auth\AuthenticationException::class,
\Illuminate\Auth\Access\AuthorizationException::class,
\Symfony\Component\HttpKernel\Exception\HttpException::class,
\Illuminate\Database\Eloquent\ModelNotFoundException::class,
\Illuminate\Session\TokenMismatchException::class,
\Illuminate\Validation\ValidationException::class,
\Symfony\Component\Console\Exception\CommandNotFoundException::class,
2018-05-09 08:05:17 -05:00
];
2019-02-21 12:08:35 -06:00
/**
2021-10-03 01:04:59 +02:00
* A list of the inputs that are never flashed for validation exceptions.
2019-02-21 12:08:35 -06:00
*
* @var array
*/
protected $upgradable = [
\LibreNMS\Exceptions\FilePermissionsException::class,
\LibreNMS\Exceptions\DatabaseConnectException::class,
\LibreNMS\Exceptions\DuskUnsafeException::class,
\LibreNMS\Exceptions\UnserializableRouteCache::class,
\LibreNMS\Exceptions\MaximumExecutionTimeExceeded::class,
\LibreNMS\Exceptions\DatabaseInconsistentException::class,
2019-02-21 12:08:35 -06:00
];
2018-05-09 08:05:17 -05:00
2020-07-09 15:22:50 +02:00
public function render($request, Throwable $exception)
2018-05-09 08:05:17 -05:00
{
2019-02-21 12:08:35 -06:00
// If for some reason Blade hasn't been registered, try it now
try {
if (! app()->bound('view')) {
app()->register(\Illuminate\View\ViewServiceProvider::class);
2019-02-21 12:08:35 -06:00
app()->register(\Illuminate\Translation\TranslationServiceProvider::class);
}
} catch (\Exception $e) {
// continue without view
}
2019-02-21 12:08:35 -06:00
// try to upgrade generic exceptions to more specific ones
if (! config('app.debug')) {
2023-04-17 13:51:35 +02:00
if ($exception instanceof \Illuminate\View\ViewException || $exception instanceof \Spatie\LaravelIgnition\Exceptions\ViewException) {
2022-04-07 21:08:43 -05:00
$base = $exception->getPrevious(); // get real exception
}
foreach ($this->upgradable as $class) {
2022-04-07 21:08:43 -05:00
if ($new = $class::upgrade($base ?? $exception)) {
return parent::render($request, $new);
}
2019-02-21 12:08:35 -06:00
}
}
2019-02-21 12:08:35 -06:00
return parent::render($request, $exception);
}
2018-07-17 15:15:11 -05:00
2020-07-09 15:22:50 +02:00
protected function convertExceptionToArray(Throwable $e)
2019-02-21 12:08:35 -06:00
{
// override the non-debug error output to clue in user on how to debug
2019-05-05 05:22:28 -05:00
if (! config('app.debug') && ! $this->isHttpException($e)) {
return ['message' => 'Server Error: Set APP_DEBUG=true to see details.'];
}
return parent::convertExceptionToArray($e);
2018-05-09 08:05:17 -05:00
}
}