mirror of
https://github.com/flarum/framework.git
synced 2024-11-29 04:33:47 +08:00
Log exceptions in error handler middleware
This commit is contained in:
parent
85bd82eab1
commit
1a2174d614
|
@ -41,12 +41,12 @@ class Server extends AbstractServer
|
|||
event(new ConfigureMiddleware($pipe, $path, $this));
|
||||
|
||||
$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 {
|
||||
$app->register('Flarum\Update\UpdateServiceProvider');
|
||||
|
||||
$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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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\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()) {
|
||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\ParseJsonBody'));
|
||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\StartSession'));
|
||||
|
@ -46,7 +46,7 @@ class Server extends AbstractServer
|
|||
event(new ConfigureMiddleware($pipe, $path, $this));
|
||||
|
||||
$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 {
|
||||
$pipe->pipe($path, function () use ($errorDir) {
|
||||
return new HtmlResponse(file_get_contents($errorDir.'/503.html', 503));
|
||||
|
|
|
@ -13,6 +13,7 @@ namespace Flarum\Http\Middleware;
|
|||
use Franzl\Middleware\Whoops\ErrorMiddleware as WhoopsMiddleware;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Zend\Diactoros\Response\HtmlResponse;
|
||||
use Zend\Stratigility\ErrorMiddlewareInterface;
|
||||
|
||||
|
@ -23,6 +24,11 @@ class HandleErrors implements ErrorMiddlewareInterface
|
|||
*/
|
||||
protected $templateDir;
|
||||
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
|
@ -30,11 +36,13 @@ class HandleErrors implements ErrorMiddlewareInterface
|
|||
|
||||
/**
|
||||
* @param string $templateDir
|
||||
* @param LoggerInterface $logger
|
||||
* @param bool $debug
|
||||
*/
|
||||
public function __construct($templateDir, $debug = false)
|
||||
public function __construct($templateDir, LoggerInterface $logger, $debug = false)
|
||||
{
|
||||
$this->templateDir = $templateDir;
|
||||
$this->logger = $logger;
|
||||
$this->debug = $debug;
|
||||
}
|
||||
|
||||
|
@ -58,6 +66,9 @@ class HandleErrors implements ErrorMiddlewareInterface
|
|||
return $whoops($error, $request, $response, $out);
|
||||
}
|
||||
|
||||
// Log the exception (with trace)
|
||||
$this->logger->debug($error);
|
||||
|
||||
$errorPage = $this->getErrorPage($status);
|
||||
|
||||
return new HtmlResponse($errorPage, $status);
|
||||
|
|
Loading…
Reference in New Issue
Block a user