diff --git a/src/Exceptions/Handler.php b/src/Exceptions/Handler.php index 045b6f1..9a2cbf7 100644 --- a/src/Exceptions/Handler.php +++ b/src/Exceptions/Handler.php @@ -3,6 +3,7 @@ namespace Rareloop\Lumberjack\Exceptions; use Exception; +use Throwable; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Rareloop\Lumberjack\Application; @@ -22,7 +23,7 @@ public function __construct(Application $app) $this->app = $app; } - public function report(Exception $e) + public function report(Throwable $e) { if ($this->shouldNotReport($e)) { return; @@ -34,16 +35,16 @@ public function report(Exception $e) } } - public function render(ServerRequestInterface $request, Exception $e) : ResponseInterface + public function render(ServerRequestInterface $request, Throwable $e): ResponseInterface { - $e = FlattenException::create($e); + $e = FlattenException::createFromThrowable($e); $handler = new SymfonyExceptionHandler(Config::get('app.debug', false)); return new HtmlResponse($handler->getHtml($e), $e->getStatusCode(), $e->getHeaders()); } - protected function shouldNotReport(Exception $e) + protected function shouldNotReport(Throwable $e) { return in_array(get_class($e), $this->dontReport); } diff --git a/src/Exceptions/HandlerInterface.php b/src/Exceptions/HandlerInterface.php index 87509b3..a0ba744 100644 --- a/src/Exceptions/HandlerInterface.php +++ b/src/Exceptions/HandlerInterface.php @@ -3,12 +3,13 @@ namespace Rareloop\Lumberjack\Exceptions; use Exception; +use Throwable; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; interface HandlerInterface { - public function report(Exception $e); + public function report(Throwable $e); - public function render(ServerRequestInterface $request, Exception $e) : ResponseInterface; + public function render(ServerRequestInterface $request, Throwable $e): ResponseInterface; } diff --git a/tests/Unit/Exceptions/HandlerTest.php b/tests/Unit/Exceptions/HandlerTest.php index dda8be0..c48da20 100644 --- a/tests/Unit/Exceptions/HandlerTest.php +++ b/tests/Unit/Exceptions/HandlerTest.php @@ -32,6 +32,22 @@ public function report_should_log_exception() $handler->report($exception); } + /** @test */ + public function report_should_log_typeerror() + { + $app = new Application; + + $exception = new \TypeError('Test Type Error'); + + $logger = Mockery::mock(Logger::class); + $logger->shouldReceive('error')->with($exception)->once(); + $app->bind('logger', $logger); + + $handler = new Handler($app); + + $handler->report($exception); + } + /** @test */ public function blacklisted_exception_types_will_not_be_logged() { @@ -65,6 +81,23 @@ public function render_should_return_an_html_response_when_debug_is_enabled() $this->assertInstanceOf(HtmlResponse::class, $response); } + /** @test */ + public function render_should_return_an_html_response_for_throwables() + { + $app = new Application; + FacadeFactory::setContainer($app); + $config = new Config; + $config->set('app.debug', true); + $app->bind('config', $config); + + $exception = new \TypeError('Test Type Error'); + $handler = new Handler($app); + + $response = $handler->render(new ServerRequest, $exception); + + $this->assertInstanceOf(HtmlResponse::class, $response); + } + /** @test */ public function render_should_return_an_html_response_when_debug_is_disabled() {