diff --git a/src/System/Integrate/Exceptions/Handler.php b/src/System/Integrate/Exceptions/Handler.php index a0fc7e55..2df721c1 100644 --- a/src/System/Integrate/Exceptions/Handler.php +++ b/src/System/Integrate/Exceptions/Handler.php @@ -102,7 +102,7 @@ protected function handleJsonResponse(\Throwable $th): Response 'code' => $respone->getStatusCode(), 'messages' => [ 'message' => $th->getMessage(), - 'exception' => get_class($th), + 'exception' => $th::class, 'file' => $th->getFile(), 'line' => $th->getLine(), ], @@ -114,13 +114,15 @@ protected function handleJsonResponse(\Throwable $th): Response protected function handleHttpException(HttpException $e): Response { - $view = $this->registerViewPath(); - $code = $view->viewExist((string) $e->getStatusCode()) + $templator = $this->registerViewPath(); + $code = $templator->viewExist((string) $e->getStatusCode()) ? $e->getStatusCode() : 500; + $this->app->set('view.instance', fn () => $templator); + $response = view((string) $code); - $response->setResponeCode($e->getStatusCode()); + $response->setResponeCode($code); $response->headers->add($e->getHeaders()); return $response; @@ -131,12 +133,11 @@ protected function handleHttpException(HttpException $e): Response */ public function registerViewPath(): Templator { - $view_path = $this->app->get('path.view'); + $view_paths = array_map(fn ($path): string => $path . 'pages/', $this->app->get('paths.view')); + $view_paths[] = $this->app->get('path.view'); /** @var TemplatorFinder */ $finder = $this->app->make(TemplatorFinder::class); - $finder->setPaths([ - $view_path . 'pages/', // find default first - ]); + $finder->setPaths($view_paths); /** @var Templator */ $view = $this->app->make('view.instance'); diff --git a/tests/Integrate/Exceptions/HandlerTest.php b/tests/Integrate/Exceptions/HandlerTest.php index 86b3764b..33d4af93 100644 --- a/tests/Integrate/Exceptions/HandlerTest.php +++ b/tests/Integrate/Exceptions/HandlerTest.php @@ -140,12 +140,13 @@ public function itCanRenderJsonForDev() public function itCanRenderHttpException() { $this->app->setViewPath('/assets/'); + $this->app->setViewPaths([ + '/assets/', + '/assets/pages/', + ]); $this->app->set( TemplatorFinder::class, - fn () => new TemplatorFinder([ - __DIR__ . '/assets', - __DIR__ . '/assets/pages', - ], ['.php', '.template.php']) + fn () => new TemplatorFinder(view_paths(), ['.php', '.template.php']) ); $this->app->set(