mirror of
https://github.com/flarum/framework.git
synced 2024-11-27 19:13:37 +08:00
Support multiple error reporters
The error handling middleware now expects an array of reporters. Extensions can register new reporters in the container like this: use Flarum\Foundation\ErrorHandling\Reporter; $container->tag(NewReporter::class, Reporter::class); Note that this is just an implementation detail and will be hidden behind an extender.
This commit is contained in:
parent
9f71e2c3cb
commit
d06493c61e
|
@ -58,7 +58,7 @@ class AdminServiceProvider extends AbstractServiceProvider
|
||||||
$pipe->pipe(new HttpMiddleware\HandleErrors(
|
$pipe->pipe(new HttpMiddleware\HandleErrors(
|
||||||
$app->make(Registry::class),
|
$app->make(Registry::class),
|
||||||
$app->inDebugMode() ? $app->make(WhoopsRenderer::class) : $app->make(ViewRenderer::class),
|
$app->inDebugMode() ? $app->make(WhoopsRenderer::class) : $app->make(ViewRenderer::class),
|
||||||
$app->make(Reporter::class)
|
$app->tagged(Reporter::class)
|
||||||
));
|
));
|
||||||
|
|
||||||
$pipe->pipe($app->make(HttpMiddleware\ParseJsonBody::class));
|
$pipe->pipe($app->make(HttpMiddleware\ParseJsonBody::class));
|
||||||
|
|
|
@ -53,7 +53,7 @@ class ApiServiceProvider extends AbstractServiceProvider
|
||||||
$pipe->pipe(new HttpMiddleware\HandleErrors(
|
$pipe->pipe(new HttpMiddleware\HandleErrors(
|
||||||
$app->make(Registry::class),
|
$app->make(Registry::class),
|
||||||
$app->make(JsonApiRenderer::class),
|
$app->make(JsonApiRenderer::class),
|
||||||
$app->make(Reporter::class)
|
$app->tagged(Reporter::class)
|
||||||
));
|
));
|
||||||
|
|
||||||
$pipe->pipe($app->make(HttpMiddleware\ParseJsonBody::class));
|
$pipe->pipe($app->make(HttpMiddleware\ParseJsonBody::class));
|
||||||
|
|
|
@ -68,7 +68,7 @@ class ForumServiceProvider extends AbstractServiceProvider
|
||||||
$pipe->pipe(new HttpMiddleware\HandleErrors(
|
$pipe->pipe(new HttpMiddleware\HandleErrors(
|
||||||
$app->make(Registry::class),
|
$app->make(Registry::class),
|
||||||
$app->inDebugMode() ? $app->make(WhoopsRenderer::class) : $app->make(ViewRenderer::class),
|
$app->inDebugMode() ? $app->make(WhoopsRenderer::class) : $app->make(ViewRenderer::class),
|
||||||
$app->make(Reporter::class)
|
$app->tagged(Reporter::class)
|
||||||
));
|
));
|
||||||
|
|
||||||
$pipe->pipe($app->make(HttpMiddleware\ParseJsonBody::class));
|
$pipe->pipe($app->make(HttpMiddleware\ParseJsonBody::class));
|
||||||
|
|
|
@ -71,6 +71,6 @@ class ErrorServiceProvider extends AbstractServiceProvider
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->app->singleton(Reporter::class, LogReporter::class);
|
$this->app->tag(LogReporter::class, Reporter::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ namespace Flarum\Http\Middleware;
|
||||||
|
|
||||||
use Flarum\Foundation\ErrorHandling\Formatter;
|
use Flarum\Foundation\ErrorHandling\Formatter;
|
||||||
use Flarum\Foundation\ErrorHandling\Registry;
|
use Flarum\Foundation\ErrorHandling\Registry;
|
||||||
use Flarum\Foundation\ErrorHandling\Reporter;
|
|
||||||
use Psr\Http\Message\ResponseInterface as Response;
|
use Psr\Http\Message\ResponseInterface as Response;
|
||||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
use Psr\Http\Server\MiddlewareInterface as Middleware;
|
use Psr\Http\Server\MiddlewareInterface as Middleware;
|
||||||
|
@ -33,15 +32,15 @@ class HandleErrors implements Middleware
|
||||||
protected $formatter;
|
protected $formatter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Reporter
|
* @var \Flarum\Foundation\ErrorHandling\Reporter[]
|
||||||
*/
|
*/
|
||||||
protected $reporter;
|
protected $reporters;
|
||||||
|
|
||||||
public function __construct(Registry $registry, Formatter $formatter, Reporter $reporter)
|
public function __construct(Registry $registry, Formatter $formatter, array $reporters)
|
||||||
{
|
{
|
||||||
$this->registry = $registry;
|
$this->registry = $registry;
|
||||||
$this->formatter = $formatter;
|
$this->formatter = $formatter;
|
||||||
$this->reporter = $reporter;
|
$this->reporters = $reporters;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,7 +54,9 @@ class HandleErrors implements Middleware
|
||||||
$error = $this->registry->handle($e);
|
$error = $this->registry->handle($e);
|
||||||
|
|
||||||
if ($error->shouldBeReported()) {
|
if ($error->shouldBeReported()) {
|
||||||
$this->reporter->report($error);
|
foreach ($this->reporters as $reporter) {
|
||||||
|
$reporter->report($error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->formatter->format($error, $request);
|
return $this->formatter->format($error, $request);
|
||||||
|
|
|
@ -43,7 +43,7 @@ class Installer implements AppInterface
|
||||||
$pipe->pipe(new HandleErrors(
|
$pipe->pipe(new HandleErrors(
|
||||||
$this->container->make(Registry::class),
|
$this->container->make(Registry::class),
|
||||||
$this->container->make(WhoopsRenderer::class),
|
$this->container->make(WhoopsRenderer::class),
|
||||||
$this->container->make(Reporter::class)
|
$this->container->tagged(Reporter::class)
|
||||||
));
|
));
|
||||||
$pipe->pipe($this->container->make(StartSession::class));
|
$pipe->pipe($this->container->make(StartSession::class));
|
||||||
$pipe->pipe(
|
$pipe->pipe(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user