forked from swarrot/swarrot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExceptionCatcherProcessor.php
40 lines (34 loc) · 1.03 KB
/
ExceptionCatcherProcessor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
namespace Swarrot\Processor\ExceptionCatcher;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Swarrot\Broker\Message;
use Swarrot\Processor\ProcessorInterface;
/**
* @final since 4.16.0
*/
class ExceptionCatcherProcessor implements ProcessorInterface
{
private ProcessorInterface $processor;
private LoggerInterface $logger;
public function __construct(ProcessorInterface $processor, ?LoggerInterface $logger = null)
{
$this->processor = $processor;
$this->logger = $logger ?: new NullLogger();
}
public function process(Message $message, array $options): bool
{
try {
return $this->processor->process($message, $options);
} catch (\Throwable $e) {
$this->logger->error(
'[ExceptionCatcher] An exception occurred. This exception has been caught.',
[
'swarrot_processor' => 'exception',
'exception' => $e,
]
);
}
return true;
}
}