mirror of
https://github.com/flarum/framework.git
synced 2024-11-28 11:34:36 +08:00
parent
9772e398f6
commit
60bdbe6e52
|
@ -37,11 +37,8 @@ class Server extends AbstractServer
|
|||
$pipe->pipe($adminPath, $app->make('Flarum\Admin\Middleware\RequireAdministrateAbility'));
|
||||
$pipe->pipe($adminPath, $app->make('Flarum\Http\Middleware\DispatchRoute', compact('routes')));
|
||||
|
||||
if ($app->inDebugMode()) {
|
||||
$pipe->pipe(new WhoopsMiddleware);
|
||||
} else {
|
||||
$pipe->pipe(new HandleErrors(__DIR__.'/../../error'));
|
||||
}
|
||||
$pipe->pipe(new HandleErrors(__DIR__.'/../../error', $app->inDebugMode()));
|
||||
|
||||
}
|
||||
|
||||
return $pipe;
|
||||
|
|
|
@ -15,7 +15,6 @@ use Flarum\Foundation\Application;
|
|||
use Flarum\Http\AbstractServer;
|
||||
use Zend\Stratigility\MiddlewarePipe;
|
||||
use Flarum\Http\Middleware\HandleErrors;
|
||||
use Franzl\Middleware\Whoops\Middleware as WhoopsMiddleware;
|
||||
|
||||
class Server extends AbstractServer
|
||||
{
|
||||
|
@ -44,11 +43,7 @@ class Server extends AbstractServer
|
|||
|
||||
$pipe->pipe($basePath, $app->make('Flarum\Http\Middleware\DispatchRoute', compact('routes')));
|
||||
|
||||
if ($app->inDebugMode() || ! $installed) {
|
||||
$pipe->pipe(new WhoopsMiddleware);
|
||||
} else {
|
||||
$pipe->pipe(new HandleErrors(__DIR__.'/../../error'));
|
||||
}
|
||||
$pipe->pipe(new HandleErrors(__DIR__.'/../../error', $app->inDebugMode() || ! $installed));
|
||||
|
||||
return $pipe;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ use Psr\Http\Message\ResponseInterface as Response;
|
|||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Zend\Diactoros\Response\HtmlResponse;
|
||||
use Zend\Stratigility\ErrorMiddlewareInterface;
|
||||
use Franzl\Middleware\Whoops\Middleware as WhoopsMiddleware;
|
||||
|
||||
class HandleErrors implements ErrorMiddlewareInterface
|
||||
{
|
||||
|
@ -23,11 +24,18 @@ class HandleErrors implements ErrorMiddlewareInterface
|
|||
protected $templateDir;
|
||||
|
||||
/**
|
||||
* @param string $templateDir
|
||||
* @var bool
|
||||
*/
|
||||
public function __construct($templateDir)
|
||||
protected $debug;
|
||||
|
||||
/**
|
||||
* @param string $templateDir
|
||||
* @param bool $debug
|
||||
*/
|
||||
public function __construct($templateDir, $debug = false)
|
||||
{
|
||||
$this->templateDir = $templateDir;
|
||||
$this->debug = $debug;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,11 +52,21 @@ class HandleErrors implements ErrorMiddlewareInterface
|
|||
$status = $errorCode;
|
||||
}
|
||||
|
||||
if ($this->debug && $errorCode !== 404) {
|
||||
$whoops = new WhoopsMiddleware;
|
||||
|
||||
return $whoops($error, $request, $response, $out);;
|
||||
}
|
||||
|
||||
$errorPage = $this->getErrorPage($status);
|
||||
|
||||
return new HtmlResponse($errorPage, $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $status
|
||||
* @return string
|
||||
*/
|
||||
protected function getErrorPage($status)
|
||||
{
|
||||
if (! file_exists($errorPage = $this->templateDir."/$status.html")) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user