diff --git a/src/aleph/vm/orchestrator/views/__init__.py b/src/aleph/vm/orchestrator/views/__init__.py index 994476cba..243138624 100644 --- a/src/aleph/vm/orchestrator/views/__init__.py +++ b/src/aleph/vm/orchestrator/views/__init__.py @@ -65,9 +65,12 @@ async def run_code_from_path(request: web.Request) -> web.Response: path = request.match_info["suffix"] path = path if path.startswith("/") else f"/{path}" - message_ref = ItemHash(request.match_info["ref"]) - pool: VmPool = request.app["vm_pool"] - return await run_code_on_request(message_ref, path, pool, request) + try: + message_ref = ItemHash(request.match_info["ref"]) + pool: VmPool = request.app["vm_pool"] + return await run_code_on_request(message_ref, path, pool, request) + except UnknownHashError as error: + raise HTTPNotFound(reason="Invalid message reference") from error async def run_code_from_hostname(request: web.Request) -> web.Response: @@ -100,6 +103,8 @@ async def run_code_from_hostname(request: web.Request) -> web.Response: logger.debug(f"Using DNS TXT record to obtain '{message_ref}'") except aiodns.error.DNSError as error: raise HTTPNotFound(reason="Invalid message reference") from error + except UnknownHashError as error: + raise HTTPNotFound(reason="Invalid message reference") from error pool = request.app["vm_pool"] return await run_code_on_request(message_ref, path, pool, request)