Skip to content

Commit

Permalink
Fix deprecated getException on Event (#69)
Browse files Browse the repository at this point in the history
* Fix deprecated getException on Event

* fix: trim whitespaces

Co-authored-by: Oliver THEBAULT <[email protected]>
  • Loading branch information
maximecolin and Oliboy50 authored Jul 26, 2020
1 parent e125929 commit 55d6a36
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Statsd/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,19 @@ public function __construct(Client $statsdClient, EventDispatcherInterface $even
*/
public function onKernelException(ExceptionEvent $event)
{
$exception = $event->getThrowable();
// @TODO: remove this backward compatibility layer after symfony 4.4 has been dropped
if (method_exists($event, 'getThrowable')) {
$exception = $event->getThrowable();
} else {
$exception = $event->getException();
}

if ($exception instanceof HttpExceptionInterface) {
$code = $event->getThrowable()->getStatusCode();
$code = $exception->getStatusCode();
} else {
$code = 'unknown';
}

$this->eventDispatcher->dispatch(
new StatsdEvent($code),
'statsd.exception'
Expand Down

0 comments on commit 55d6a36

Please sign in to comment.