1
0
mirror of https://github.com/flarum/core.git synced 2025-08-06 08:27:42 +02:00

Catch Throwables so that we handle internal PHP errors too

This commit is contained in:
Toby Zerner
2018-11-11 17:54:19 +10:30
parent 66404e1f61
commit 295a007cd5
4 changed files with 13 additions and 8 deletions

View File

@@ -11,7 +11,6 @@
namespace Flarum\Http\Middleware;
use Exception;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\View\Factory as ViewFactory;
use Psr\Http\Message\ResponseInterface as Response;
@@ -20,6 +19,7 @@ use Psr\Http\Server\MiddlewareInterface as Middleware;
use Psr\Http\Server\RequestHandlerInterface as Handler;
use Psr\Log\LoggerInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Throwable;
use Zend\Diactoros\Response\HtmlResponse;
class HandleErrorsWithView implements Middleware
@@ -65,12 +65,12 @@ class HandleErrorsWithView implements Middleware
{
try {
return $handler->handle($request);
} catch (Exception $e) {
} catch (Throwable $e) {
return $this->formatException($e);
}
}
protected function formatException(Exception $error)
protected function formatException(Throwable $error)
{
$status = 500;
$errorCode = $error->getCode();

View File

@@ -11,12 +11,12 @@
namespace Flarum\Http\Middleware;
use Exception;
use Franzl\Middleware\Whoops\WhoopsRunner;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface as Middleware;
use Psr\Http\Server\RequestHandlerInterface as Handler;
use Throwable;
class HandleErrorsWithWhoops implements Middleware
{
@@ -27,7 +27,7 @@ class HandleErrorsWithWhoops implements Middleware
{
try {
return $handler->handle($request);
} catch (Exception $e) {
} catch (Throwable $e) {
return WhoopsRunner::handle($e, $request);
}
}