Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
23 / 23 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| SignRequestErrorReporter | |
100.00% |
23 / 23 |
|
100.00% |
3 / 3 |
9 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| log | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| maybeStoreProgressError | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
7 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | /** |
| 5 | * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors |
| 6 | * SPDX-License-Identifier: AGPL-3.0-or-later |
| 7 | */ |
| 8 | |
| 9 | namespace OCA\Libresign\Service\SignRequest\Error; |
| 10 | |
| 11 | use OCA\Libresign\Service\SignRequest\ProgressService; |
| 12 | use Psr\Log\AbstractLogger; |
| 13 | use Psr\Log\LoggerInterface; |
| 14 | use Psr\Log\LogLevel; |
| 15 | |
| 16 | class SignRequestErrorReporter extends AbstractLogger { |
| 17 | public function __construct( |
| 18 | private ProgressService $progressService, |
| 19 | private LoggerInterface $logger, |
| 20 | ) { |
| 21 | } |
| 22 | |
| 23 | #[\Override] |
| 24 | public function log($level, $message, array $context = []): void { |
| 25 | $this->maybeStoreProgressError($level, $context); |
| 26 | $this->logger->log($level, $message, $context); |
| 27 | } |
| 28 | |
| 29 | private function maybeStoreProgressError(string $level, array $context): void { |
| 30 | if ($level !== LogLevel::ERROR) { |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | $exception = $context['exception'] ?? null; |
| 35 | if (!$exception instanceof \Throwable) { |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | $signRequestUuid = $context['signRequestUuid'] ?? null; |
| 40 | if (empty($signRequestUuid)) { |
| 41 | return; |
| 42 | } |
| 43 | |
| 44 | $ttl = (int)($context['ttl'] ?? ProgressService::ERROR_CACHE_TTL); |
| 45 | $fileId = $context['fileId'] ?? null; |
| 46 | $signRequestId = $context['signRequestId'] ?? null; |
| 47 | $payload = ErrorPayloadBuilder::fromException( |
| 48 | e: $exception, |
| 49 | fileId: is_numeric($fileId) ? (int)$fileId : null, |
| 50 | signRequestId: is_numeric($signRequestId) ? (int)$signRequestId : null, |
| 51 | signRequestUuid: $signRequestUuid |
| 52 | )->build(); |
| 53 | |
| 54 | $this->progressService->setSignRequestError($signRequestUuid, $payload, $ttl); |
| 55 | if (is_numeric($fileId)) { |
| 56 | $this->progressService->setFileError($signRequestUuid, (int)$fileId, $payload, $ttl); |
| 57 | } |
| 58 | } |
| 59 | } |