Skip to content

Commit

Permalink
error handling improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Jupiter committed Feb 28, 2019
1 parent 31f1f5f commit 8a72e1c
Show file tree
Hide file tree
Showing 4 changed files with 367 additions and 307 deletions.
13 changes: 12 additions & 1 deletion app/Handlers/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
final class Error extends \Slim\Handlers\Error
{

/**
* @param \Psr\Http\Message\ServerRequestInterface $request
* @param \Psr\Http\Message\ResponseInterface $response
* @param \Exception $exception
*
* @return \Psr\Http\Message\ResponseInterface
* @throws \ReflectionException
* @throws \Exception
*/
public function __invoke(Request $request, Response $response, \Exception $exception)
{
$app = app();
Expand All @@ -20,7 +29,9 @@ public function __invoke(Request $request, Response $response, \Exception $excep
$app->resolve(LoggerInterface::class)->error($exception);
}

if (class_exists(SlashTrace::class) && ($app->isConsole() || $this->displayErrorDetails)) {
if (app()->has('slashtrace') && ($app->isConsole() || $this->displayErrorDetails)) {
app()->resolve('slashtrace')->register();
http_response_code(500);
throw $exception;
}

Expand Down
13 changes: 12 additions & 1 deletion app/Handlers/PhpError.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
final class PhpError extends \Slim\Handlers\PhpError
{

/**
* @param \Psr\Http\Message\ServerRequestInterface $request
* @param \Psr\Http\Message\ResponseInterface $response
* @param \Throwable $error
*
* @return \Psr\Http\Message\ResponseInterface
* @throws \ReflectionException
* @throws \Throwable
*/
public function __invoke(Request $request, Response $response, \Throwable $error)
{
$app = app();
Expand All @@ -20,7 +29,9 @@ public function __invoke(Request $request, Response $response, \Throwable $error
$app->resolve(LoggerInterface::class)->error($error);
}

if (class_exists(SlashTrace::class) && ($app->isConsole() || $this->displayErrorDetails)) {
if (app()->has('slashtrace') && ($app->isConsole() || $this->displayErrorDetails)) {
app()->resolve('slashtrace')->register();
http_response_code(500);
throw $error;
}

Expand Down
13 changes: 4 additions & 9 deletions app/ServiceProviders/SlashTrace.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,16 @@
namespace App\ServiceProviders;
use SlashTrace\SlashTrace as ST;
use SlashTrace\EventHandler\DebugHandler;
use SlashTrace\DebugRenderer\DebugCliRenderer;

class SlashTrace implements ProviderInterface
{

public static function register()
{
$d = new DebugHandler();
if (php_sapi_name() === "cli") $d->setRenderer(new DebugCliRenderer());

public static function register()
{
$st = new ST();
$st->addHandler($d);
$st->register();
$st->addHandler(new DebugHandler());

app()->getContainer()['slashtrace'] = $st;
}
}

}
Loading

0 comments on commit 8a72e1c

Please sign in to comment.