From 0ce33c3ec0a7832b20b7eb07bccbd1c7be17888e Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Fri, 11 Aug 2023 14:20:18 +0100 Subject: [PATCH] chore: adapt whoops formatter --- .../src/Foundation/ErrorHandling/HttpFormatter.php | 4 ++-- .../src/Foundation/ErrorHandling/JsonApiFormatter.php | 4 ++-- .../src/Foundation/ErrorHandling/ViewFormatter.php | 6 +++--- .../src/Foundation/ErrorHandling/WhoopsFormatter.php | 11 ++++++++--- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/framework/core/src/Foundation/ErrorHandling/HttpFormatter.php b/framework/core/src/Foundation/ErrorHandling/HttpFormatter.php index 812c44655..233734f4e 100644 --- a/framework/core/src/Foundation/ErrorHandling/HttpFormatter.php +++ b/framework/core/src/Foundation/ErrorHandling/HttpFormatter.php @@ -9,8 +9,8 @@ namespace Flarum\Foundation\ErrorHandling; -use Psr\Http\Message\ResponseInterface as Response; -use Psr\Http\Message\ServerRequestInterface as Request; +use Illuminate\Http\Request; +use Symfony\Component\HttpFoundation\Response; interface HttpFormatter { diff --git a/framework/core/src/Foundation/ErrorHandling/JsonApiFormatter.php b/framework/core/src/Foundation/ErrorHandling/JsonApiFormatter.php index e6276c44a..411baacb0 100644 --- a/framework/core/src/Foundation/ErrorHandling/JsonApiFormatter.php +++ b/framework/core/src/Foundation/ErrorHandling/JsonApiFormatter.php @@ -10,8 +10,8 @@ namespace Flarum\Foundation\ErrorHandling; use Flarum\Api\JsonApiResponse; -use Psr\Http\Message\ResponseInterface as Response; -use Psr\Http\Message\ServerRequestInterface as Request; +use Illuminate\Http\Request; +use Symfony\Component\HttpFoundation\Response; use Tobscure\JsonApi\Document; /** diff --git a/framework/core/src/Foundation/ErrorHandling/ViewFormatter.php b/framework/core/src/Foundation/ErrorHandling/ViewFormatter.php index ad0b31b15..ab4b9a3e0 100644 --- a/framework/core/src/Foundation/ErrorHandling/ViewFormatter.php +++ b/framework/core/src/Foundation/ErrorHandling/ViewFormatter.php @@ -12,9 +12,9 @@ namespace Flarum\Foundation\ErrorHandling; use Flarum\Locale\TranslatorInterface; use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Http\Request; use Laminas\Diactoros\Response\HtmlResponse; -use Psr\Http\Message\ResponseInterface as Response; -use Psr\Http\Message\ServerRequestInterface as Request; +use Symfony\Component\HttpFoundation\Response; /** * A formatter for turning caught exceptions into "pretty" HTML error pages. @@ -45,7 +45,7 @@ class ViewFormatter implements HttpFormatter ->with('error', $error->getException()) ->with('message', $this->getMessage($error)); - return new HtmlResponse($view->render(), $error->getStatusCode()); + return new \Illuminate\Http\Response($view->render(), $error->getStatusCode()); } private function determineView(HandledError $error): string diff --git a/framework/core/src/Foundation/ErrorHandling/WhoopsFormatter.php b/framework/core/src/Foundation/ErrorHandling/WhoopsFormatter.php index 8a9201058..0508774fe 100644 --- a/framework/core/src/Foundation/ErrorHandling/WhoopsFormatter.php +++ b/framework/core/src/Foundation/ErrorHandling/WhoopsFormatter.php @@ -9,9 +9,10 @@ namespace Flarum\Foundation\ErrorHandling; +use Flarum\Http\RequestUtil; use Franzl\Middleware\Whoops\WhoopsRunner; -use Psr\Http\Message\ResponseInterface as Response; -use Psr\Http\Message\ServerRequestInterface as Request; +use Illuminate\Http\Request; +use Symfony\Component\HttpFoundation\Response; /** * Handle errors using the Whoops error handler for debugging. @@ -26,7 +27,11 @@ class WhoopsFormatter implements HttpFormatter { public function format(HandledError $error, Request $request): Response { - return WhoopsRunner::handle($error->getException(), $request) + $psr7Request = RequestUtil::toPsr7($request); + + $psr7Response = WhoopsRunner::handle($error->getException(), $psr7Request) ->withStatus($error->getStatusCode()); + + return RequestUtil::responseToSymfony($psr7Response); } }