]> BookStack Code Mirror - bookstack/blob - app/Exceptions/BookStackExceptionHandlerPage.php
API: Added system read endpoint
[bookstack] / app / Exceptions / BookStackExceptionHandlerPage.php
1 <?php
2
3 namespace BookStack\Exceptions;
4
5 use BookStack\App\AppVersion;
6 use Illuminate\Contracts\Foundation\ExceptionRenderer;
7
8 class BookStackExceptionHandlerPage implements ExceptionRenderer
9 {
10     public function render($throwable)
11     {
12         return view('errors.debug', [
13             'error'       => $throwable->getMessage(),
14             'errorClass'  => get_class($throwable),
15             'trace'       => $throwable->getTraceAsString(),
16             'environment' => $this->getEnvironment(),
17         ])->render();
18     }
19
20     protected function safeReturn(callable $callback, $default = null)
21     {
22         try {
23             return $callback();
24         } catch (\Exception $e) {
25             return $default;
26         }
27     }
28
29     protected function getEnvironment(): array
30     {
31         return [
32             'PHP Version'       => phpversion(),
33             'BookStack Version' => $this->safeReturn(function () {
34                 return AppVersion::get();
35             }, 'unknown'),
36             'Theme Configured' => $this->safeReturn(function () {
37                 return config('view.theme');
38             }) ?? 'None',
39         ];
40     }
41 }