<?php
namespace Daniel230\FirehouseInterface\Services;
use Daniel230\FirehouseInterface\Firehouse;
class ExceptionHandlerService
{
public function onSymfonyException($event)
{
if (
class_exists('Symfony\Component\HttpKernel\Event\ExceptionEvent') &&
$event instanceof \Symfony\Component\HttpKernel\Event\ExceptionEvent
) {
$request = $event->getRequest();
$ip = $request->getClientIp();
$throwable = $event->getThrowable();
// Convert the Throwable to an Exception if necessary
if ($throwable instanceof \Throwable) {
$throwable = new \Exception($throwable->getMessage(), $throwable->getCode(), $throwable);
}
// Report the error using Firehouse
$firehouse = new Firehouse();
$firehouse->reportError($throwable, function ($error) use ($ip) {
$error->setRequestIp($ip);
});;
}
}
}