SentryMiddleware::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
c 1
b 0
f 0
dl 0
loc 2
ccs 1
cts 1
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Sentry;
6
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Psr\Http\Server\MiddlewareInterface;
10
use Psr\Http\Server\RequestHandlerInterface;
11
use Sentry\State\HubInterface;
12
use Throwable;
13
14
/**
15
 * Catches web application exceptions and forwards them to Sentry.
16
 * In order to catch all exceptions, add it right after `ErrorCatcher` in the main middleware set.
17
 */
18
final class SentryMiddleware implements MiddlewareInterface
19
{
20 4
    public function __construct(private HubInterface $hub)
21
    {
22 4
    }
23
24 4
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
25
    {
26
        try {
27 4
            return $handler->handle($request);
28 3
        } catch (Throwable $e) {
29 3
            $this->hub->captureException($e);
30 3
            throw $e;
31
        }
32
    }
33
}
34