Fixed event handler not being properly registered as a service

This commit is contained in:
Alejandro Celaya
2019-07-13 15:43:54 +02:00
parent 91698034e7
commit 4380b62715
4 changed files with 40 additions and 4 deletions

View File

@@ -5,6 +5,7 @@ namespace Shlinkio\Shlink\Core\EventDispatcher;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Shlinkio\Shlink\Common\Exception\WrongIpException;
use Shlinkio\Shlink\Common\IpGeolocation\IpLocationResolverInterface;
use Shlinkio\Shlink\Common\IpGeolocation\Model\Location;
use Shlinkio\Shlink\Core\Entity\Visit;
@@ -42,9 +43,17 @@ class LocateShortUrlVisit
return;
}
$location = $visit->isLocatable()
? $this->ipLocationResolver->resolveIpLocation($visit->getRemoteAddr())
: Location::emptyInstance();
try {
$location = $visit->isLocatable()
? $this->ipLocationResolver->resolveIpLocation($visit->getRemoteAddr())
: Location::emptyInstance();
} catch (WrongIpException $e) {
$this->logger->warning(
sprintf('Tried to locate visit with id "%s", but its address seems to be wrong. {e}', $visitId),
['e' => $e]
);
return;
}
$visit->locate(new VisitLocation($location));
$this->em->flush($visit);