mirror of
https://github.com/flarum/framework.git
synced 2025-02-01 19:23:58 +08:00
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.
This commit is contained in:
parent
840e740309
commit
43c551929b
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user