diff --git a/src/Controller/TorrentController.php b/src/Controller/TorrentController.php index f720fdd..2fdd907 100644 --- a/src/Controller/TorrentController.php +++ b/src/Controller/TorrentController.php @@ -45,7 +45,7 @@ class TorrentController extends AbstractController } // Read file - if (!$file = $torrentService->readTorrentFileById($torrent->getId())) + if (!$file = $torrentService->readTorrentFileByTorrentId($torrent->getId())) { throw $this->createNotFoundException(); } diff --git a/src/Service/TorrentService.php b/src/Service/TorrentService.php index 1f68a3a..9a6762f 100644 --- a/src/Service/TorrentService.php +++ b/src/Service/TorrentService.php @@ -32,14 +32,22 @@ class TorrentService // Tools public function readTorrentFileByFilepath( string $filepath - ): \Rhilip\Bencode\TorrentFile + ): ?\Rhilip\Bencode\TorrentFile { - return \Rhilip\Bencode\TorrentFile::load( - $filepath - ); + try + { + return \Rhilip\Bencode\TorrentFile::load( + $filepath + ); + } + + catch (\Rhilip\Bencode\ParseException $error) + { + return null; + } } - public function readTorrentFileById( + public function readTorrentFileByTorrentId( int $id ): \Rhilip\Bencode\TorrentFile {