diff --git a/src/System/Integrate/Exceptions/Handler.php b/src/System/Integrate/Exceptions/Handler.php index 2df721c1..006384e8 100644 --- a/src/System/Integrate/Exceptions/Handler.php +++ b/src/System/Integrate/Exceptions/Handler.php @@ -57,6 +57,10 @@ public function render(Request $request, \Throwable $th): Response return $this->handleHttpException($th); } + if (false === $this->isDebug()) { + return $this->handleResponse($th); + } + throw $th; } @@ -97,7 +101,7 @@ protected function handleJsonResponse(\Throwable $th): Response $respone->headers->add($th->getHeaders()); } - if ($this->isDev()) { + if ($this->isDebug()) { return $respone->json([ 'code' => $respone->getStatusCode(), 'messages' => [ @@ -112,6 +116,11 @@ protected function handleJsonResponse(\Throwable $th): Response return $respone->json(); } + protected function handleResponse(\Throwable $th): Response + { + return new Response($th->getMessage(), 500); + } + protected function handleHttpException(HttpException $e): Response { $templator = $this->registerViewPath(); @@ -146,8 +155,8 @@ public function registerViewPath(): Templator return $view; } - private function isDev(): bool + private function isDebug(): bool { - return 'dev' === $this->app->get('environment'); + return $this->app->get('app.debug') ?? false; } } diff --git a/tests/Integrate/Exceptions/HandlerTest.php b/tests/Integrate/Exceptions/HandlerTest.php index a7a74f04..09d4af1f 100644 --- a/tests/Integrate/Exceptions/HandlerTest.php +++ b/tests/Integrate/Exceptions/HandlerTest.php @@ -114,7 +114,7 @@ public function itCanReportException() public function itCanRenderJson() { $this->app->bootedCallback(function () { - $this->app->set('environment', 'prod'); + $this->app->set('app.debug', false); }); $karnel = $this->app->make(Karnel::class); @@ -132,9 +132,12 @@ public function itCanRenderJson() } /** @test */ - public function itCanRenderJsonForDev() + public function itCanRenderJsonForDebug() { - $this->app->set('environment', 'dev'); + $this->app->bootedCallback(function () { + $this->app->set('app.debug', true); + }); + $karnel = $this->app->make(Karnel::class); $response = $karnel->handle(new Request('/test', [], [], [], [], [], [ 'content-type' => 'application/json',