Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Exceptions/HandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
33 changes: 33 additions & 0 deletions tests/Unit/Exceptions/HandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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()
{
Expand Down