diff --git a/frontik/handler_asgi.py b/frontik/handler_asgi.py index d08238451..8c9676866 100644 --- a/frontik/handler_asgi.py +++ b/frontik/handler_asgi.py @@ -161,7 +161,10 @@ async def send(message): else: raise RuntimeError(f'Unsupported response type "{message["type"]}" for asgi app') - await asgi_app(scope, receive, send) + try: + await asgi_app(scope, receive, send) + except Exception: + log.exception('failed to execute page') return response diff --git a/tests/test_errors.py b/tests/test_errors.py index 658b50b64..3da059942 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -12,6 +12,15 @@ async def get_page(code: int = 200) -> None: raise HTTPException(code) +class SomeException(Exception): + pass + + +@router.get('/some_exception') +async def some_exception_page() -> None: + raise SomeException() + + class TestHttpError(FrontikTestBase): @pytest.fixture(scope='class') def frontik_app(self) -> FrontikApplication: @@ -33,3 +42,7 @@ async def test_405(self): response = await self.fetch('/http_exception', method='PUT') assert response.status_code == 405 assert response.headers['allow'] == 'GET' + + async def test_some_exception(self): + response = await self.fetch('/some_exception') + assert response.status_code == 500