1
0
mirror of https://github.com/flarum/core.git synced 2025-07-20 00:01:17 +02:00

Log exceptions in error handler middleware

This commit is contained in:
Franz Liedke
2016-06-12 17:22:28 +09:00
parent 6e95762236
commit a57c337a24
3 changed files with 16 additions and 5 deletions

View File

@@ -41,12 +41,12 @@ class Server extends AbstractServer
event(new ConfigureMiddleware($pipe, $path, $this)); event(new ConfigureMiddleware($pipe, $path, $this));
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.admin.routes')])); $pipe->pipe($path, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.admin.routes')]));
$pipe->pipe($path, new HandleErrors($errorDir, $app->inDebugMode())); $pipe->pipe($path, new HandleErrors($errorDir, $app->make('log'), $app->inDebugMode()));
} else { } else {
$app->register('Flarum\Update\UpdateServiceProvider'); $app->register('Flarum\Update\UpdateServiceProvider');
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.update.routes')])); $pipe->pipe($path, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.update.routes')]));
$pipe->pipe($path, new HandleErrors($errorDir, true)); $pipe->pipe($path, new HandleErrors($errorDir, $app->make('log'), true));
} }
} }

View File

@@ -35,7 +35,7 @@ class Server extends AbstractServer
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\StartSession')); $pipe->pipe($path, $app->make('Flarum\Http\Middleware\StartSession'));
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.install.routes')])); $pipe->pipe($path, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.install.routes')]));
$pipe->pipe($path, new HandleErrors($errorDir, true)); $pipe->pipe($path, new HandleErrors($errorDir, $app->make('log'), true));
} elseif ($app->isUpToDate() && ! $app->isDownForMaintenance()) { } elseif ($app->isUpToDate() && ! $app->isDownForMaintenance()) {
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\ParseJsonBody')); $pipe->pipe($path, $app->make('Flarum\Http\Middleware\ParseJsonBody'));
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\StartSession')); $pipe->pipe($path, $app->make('Flarum\Http\Middleware\StartSession'));
@@ -46,7 +46,7 @@ class Server extends AbstractServer
event(new ConfigureMiddleware($pipe, $path, $this)); event(new ConfigureMiddleware($pipe, $path, $this));
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.forum.routes')])); $pipe->pipe($path, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.forum.routes')]));
$pipe->pipe($path, new HandleErrors($errorDir, $app->inDebugMode())); $pipe->pipe($path, new HandleErrors($errorDir, $app->make('log'), $app->inDebugMode()));
} else { } else {
$pipe->pipe($path, function () use ($errorDir) { $pipe->pipe($path, function () use ($errorDir) {
return new HtmlResponse(file_get_contents($errorDir.'/503.html', 503)); return new HtmlResponse(file_get_contents($errorDir.'/503.html', 503));

View File

@@ -13,6 +13,7 @@ namespace Flarum\Http\Middleware;
use Franzl\Middleware\Whoops\ErrorMiddleware as WhoopsMiddleware; use Franzl\Middleware\Whoops\ErrorMiddleware as WhoopsMiddleware;
use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Log\LoggerInterface;
use Zend\Diactoros\Response\HtmlResponse; use Zend\Diactoros\Response\HtmlResponse;
use Zend\Stratigility\ErrorMiddlewareInterface; use Zend\Stratigility\ErrorMiddlewareInterface;
@@ -23,6 +24,11 @@ class HandleErrors implements ErrorMiddlewareInterface
*/ */
protected $templateDir; protected $templateDir;
/**
* @var LoggerInterface
*/
protected $logger;
/** /**
* @var bool * @var bool
*/ */
@@ -30,11 +36,13 @@ class HandleErrors implements ErrorMiddlewareInterface
/** /**
* @param string $templateDir * @param string $templateDir
* @param LoggerInterface $logger
* @param bool $debug * @param bool $debug
*/ */
public function __construct($templateDir, $debug = false) public function __construct($templateDir, LoggerInterface $logger, $debug = false)
{ {
$this->templateDir = $templateDir; $this->templateDir = $templateDir;
$this->logger = $logger;
$this->debug = $debug; $this->debug = $debug;
} }
@@ -58,6 +66,9 @@ class HandleErrors implements ErrorMiddlewareInterface
return $whoops($error, $request, $response, $out); return $whoops($error, $request, $response, $out);
} }
// Log the exception (with trace)
$this->logger->debug($error);
$errorPage = $this->getErrorPage($status); $errorPage = $this->getErrorPage($status);
return new HtmlResponse($errorPage, $status); return new HtmlResponse($errorPage, $status);