Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@notFloran
Created June 7, 2017 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notFloran/c0e5f6290c498c5bc18ae188ecd389f8 to your computer and use it in GitHub Desktop.
Save notFloran/c0e5f6290c498c5bc18ae188ecd389f8 to your computer and use it in GitHub Desktop.
SentryExceptionCatcherProcessor for Swarrot
<?php
namespace Hexanet\Si\AppBundle\Processor\Swarrot;
use Swarrot\Broker\Message;
use Swarrot\Processor\ProcessorInterface;
class SentryExceptionCatcherProcessor implements ProcessorInterface
{
/**
* @var ProcessorInterface
*/
private $processor;
/**
* @var \Raven_Client|null
*/
private $client;
/**
* @param ProcessorInterface $processor
* @param \Raven_Client|null $client
*/
public function __construct(ProcessorInterface $processor, \Raven_Client $client = null)
{
$this->processor = $processor;
$this->client = $client;
}
/**
* {@inheritdoc}
*/
public function process(Message $message, array $options)
{
try {
return $this->processor->process($message, $options);
} catch (\Throwable $e) {
$this->handleException($e, $message, $options);
} catch (\Exception $e) {
$this->handleException($e, $message, $options);
}
}
/**
* @param \Throwable|\Exception $exception
* @param Message $message
* @param array $options
*
* @throws \Throwable|\Exception
*/
private function handleException($exception, Message $message, array $options)
{
$properties = $message->getProperties();
$data = [
'tags' => [
'routing_key' => $properties['routing_key'] ?? '',
'queue' => $options['queue'] ?? '',
],
'extra' => [
'message' => $message->getBody(),
]
];
$this->client and $this->client->captureException($exception, $data);
throw $exception;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment