From 5ef3bacdfd3f3050e9733c549a684f24cc7cef07 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Sat, 7 Dec 2019 01:16:48 +0100 Subject: [PATCH] Catch more exceptions during boot process This extends our boot exception handling block to also catch and format all exceptions that could be thrown while building our request handler, i.e. the middleware stack handling requests. The only exceptions that would now not be handled in this way could be raised by Zend's `RequestHandlerRunner` and its delegates, which we should be able to rely on. Exceptions on request execution will be handled by the error handler in the middleware stack. Fixes #1607. --- framework/core/src/Http/Server.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/framework/core/src/Http/Server.php b/framework/core/src/Http/Server.php index 792cd148b..efd98150c 100644 --- a/framework/core/src/Http/Server.php +++ b/framework/core/src/Http/Server.php @@ -29,10 +29,8 @@ class Server public function listen() { - $app = $this->safelyBootApp(); - $runner = new RequestHandlerRunner( - $app->getRequestHandler(), + $this->safelyBootAndGetHandler(), new SapiEmitter, [ServerRequestFactory::class, 'fromGlobals'], function (Throwable $e) { @@ -45,14 +43,17 @@ class Server } /** - * Try to boot Flarum, and prevent exceptions from exposing sensitive info. + * Try to boot Flarum, and retrieve the app's HTTP request handler. * - * @return \Flarum\Foundation\AppInterface + * We catch all exceptions happening during this process and format them to + * prevent exposure of sensitive information. + * + * @return \Psr\Http\Server\RequestHandlerInterface */ - private function safelyBootApp() + private function safelyBootAndGetHandler() { try { - return $this->site->bootApp(); + return $this->site->bootApp()->getRequestHandler(); } catch (Throwable $e) { exit($this->formatBootException($e)); }