1
0
mirror of https://github.com/flarum/core.git synced 2025-08-08 09:26:34 +02:00

Update to Zend Stratigility 1.3

* Fix dependency version constraint. (Reverts #1066.)
* Allow exceptions to be raised when dispatching middleware.
* Fix our error handler middleware (do not implement Stratigility's
  error handler interface, catch exceptions instead).

See https://docs.zendframework.com/zend-stratigility/migration/to-v2/.

Closes #1069.
This commit is contained in:
Franz Liedke
2017-01-02 22:54:55 +01:00
parent ec8ae6e03b
commit b5b18dd436
7 changed files with 47 additions and 15 deletions

View File

@@ -26,6 +26,7 @@ class FullStackServer extends AbstractServer
protected function getMiddleware(Application $app)
{
$pipe = new MiddlewarePipe;
$pipe->raiseThrowables();
$pipe->pipe(new ApiServer);
$pipe->pipe(new AdminServer);

View File

@@ -11,14 +11,14 @@
namespace Flarum\Http\Middleware;
use Exception;
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;
class HandleErrors implements ErrorMiddlewareInterface
class HandleErrors
{
/**
* @var string
@@ -48,9 +48,23 @@ class HandleErrors implements ErrorMiddlewareInterface
}
/**
* {@inheritdoc}
* Catch all errors that happen during further middleware execution.
*
* @param Request $request
* @param Response $response
* @param callable $out
* @return Response
*/
public function __invoke($error, Request $request, Response $response, callable $out = null)
public function __invoke(Request $request, Response $response, callable $out = null)
{
try {
return $out($request, $response);
} catch (Exception $e) {
return $this->formatException($e);
}
}
protected function formatException(Exception $error)
{
$status = 500;
$errorCode = $error->getCode();