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