diff --git a/src/tribler/core/components/libtorrent/restapi/tests/test_torrentinfo_endpoint.py b/src/tribler/core/components/libtorrent/restapi/tests/test_torrentinfo_endpoint.py index d4b18ecca79..c998843f5ac 100644 --- a/src/tribler/core/components/libtorrent/restapi/tests/test_torrentinfo_endpoint.py +++ b/src/tribler/core/components/libtorrent/restapi/tests/test_torrentinfo_endpoint.py @@ -92,6 +92,9 @@ def verify_valid_dict(json_data): # Corrupt file await do_request(rest_api, url, params={'uri': _path('test_rss.xml')}, expected_code=500) + # Non-existing file + await do_request(rest_api, url, params={'uri': _path('non_existing.torrent')}, expected_code=500) + path = "http://localhost:1234/ubuntu.torrent" async def mock_http_query(*_): diff --git a/src/tribler/core/components/libtorrent/restapi/torrentinfo_endpoint.py b/src/tribler/core/components/libtorrent/restapi/torrentinfo_endpoint.py index f0bc1b10a32..435d1dc2531 100644 --- a/src/tribler/core/components/libtorrent/restapi/torrentinfo_endpoint.py +++ b/src/tribler/core/components/libtorrent/restapi/torrentinfo_endpoint.py @@ -93,7 +93,7 @@ async def get_torrent_info(self, request): try: tdef = TorrentDef.load(file) metainfo = tdef.metainfo - except (TypeError, ValueError, RuntimeError): + except (FileNotFoundError, TypeError, ValueError, RuntimeError): return RESTResponse({"error": f"error while decoding torrent file: {file}"}, status=HTTP_INTERNAL_SERVER_ERROR) elif scheme in (HTTP_SCHEME, HTTPS_SCHEME):