2021-10-14 10:33:08 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Exceptions;
|
|
|
|
|
|
|
|
use Whoops\Handler\Handler;
|
|
|
|
|
|
|
|
class WhoopsBookStackPrettyHandler extends Handler
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return int|null A handler may return nothing, or a Handler::HANDLE_* constant
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$exception = $this->getException();
|
2021-10-14 12:40:22 -04:00
|
|
|
|
2021-10-14 10:33:08 -04:00
|
|
|
echo view('errors.debug', [
|
2021-10-15 09:16:45 -04:00
|
|
|
'error' => $exception->getMessage(),
|
|
|
|
'errorClass' => get_class($exception),
|
|
|
|
'trace' => $exception->getTraceAsString(),
|
2021-10-14 10:33:08 -04:00
|
|
|
'environment' => $this->getEnvironment(),
|
|
|
|
])->render();
|
2021-10-14 12:40:22 -04:00
|
|
|
|
2021-10-14 10:33:08 -04:00
|
|
|
return Handler::QUIT;
|
|
|
|
}
|
|
|
|
|
2021-10-15 09:16:45 -04:00
|
|
|
protected function safeReturn(callable $callback, $default = null)
|
|
|
|
{
|
2021-10-14 10:33:08 -04:00
|
|
|
try {
|
|
|
|
return $callback();
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getEnvironment(): array
|
|
|
|
{
|
|
|
|
return [
|
2021-10-15 09:16:45 -04:00
|
|
|
'PHP Version' => phpversion(),
|
|
|
|
'BookStack Version' => $this->safeReturn(function () {
|
2021-10-14 10:33:08 -04:00
|
|
|
$versionFile = base_path('version');
|
2021-10-15 09:16:45 -04:00
|
|
|
|
2021-10-14 10:33:08 -04:00
|
|
|
return trim(file_get_contents($versionFile));
|
|
|
|
}, 'unknown'),
|
2021-10-15 09:16:45 -04:00
|
|
|
'Theme Configured' => $this->safeReturn(function () {
|
|
|
|
return config('view.theme');
|
|
|
|
}) ?? 'None',
|
2021-10-14 10:33:08 -04:00
|
|
|
];
|
|
|
|
}
|
2021-10-15 09:16:45 -04:00
|
|
|
}
|