Skip to content

Commit 95c8e94

Browse files
author
Andrei Neagu
committed
foixed exceptions
1 parent 209143b commit 95c8e94

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/exceptions/handlers/_http_error.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
from collections.abc import Callable
33
from typing import Awaitable
44

5-
from fastapi import HTTPException, Request, status
5+
from fastapi import HTTPException, status
66
from fastapi.encoders import jsonable_encoder
77
from servicelib.logging_errors import create_troubleshotting_log_kwargs
88
from servicelib.status_codes_utils import is_5xx_server_error
9+
from starlette.requests import Request
910
from starlette.responses import JSONResponse
1011

1112
from ...exceptions.errors import RutNotFoundError
@@ -34,8 +35,9 @@ async def http_error_handler(request: Request, exc: Exception) -> JSONResponse:
3435

3536
def http404_error_handler(
3637
_: Request, # pylint: disable=unused-argument
37-
exc: RutNotFoundError,
38+
exc: Exception,
3839
) -> JSONResponse:
40+
assert isinstance(exc, RutNotFoundError) # nose
3941
return JSONResponse(
4042
status_code=status.HTTP_404_NOT_FOUND,
4143
content={"message": f"{exc.msg_template}"},
@@ -44,15 +46,15 @@ def http404_error_handler(
4446

4547
def make_http_error_handler_for_exception(
4648
status_code: int, exception_cls: type[BaseException]
47-
) -> Callable[[Request, type[BaseException]], Awaitable[JSONResponse]]:
49+
) -> Callable[[Request, Exception], Awaitable[JSONResponse]]:
4850
"""
4951
Produces a handler for BaseException-type exceptions which converts them
5052
into an error JSON response with a given status code
5153
5254
SEE https://docs.python.org/3/library/exceptions.html#concrete-exceptions
5355
"""
5456

55-
async def _http_error_handler(_: Request, exc: type[BaseException]) -> JSONResponse:
57+
async def _http_error_handler(_: Request, exc: Exception) -> JSONResponse:
5658
assert isinstance(exc, exception_cls) # nosec
5759
return JSONResponse(
5860
content=jsonable_encoder({"errors": [str(exc)]}), status_code=status_code

services/resource-usage-tracker/tests/unit/with_dbs/test_api_resource_tracker_service_runs__export.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import pytest
1010
import sqlalchemy as sa
1111
from moto.server import ThreadedMotoServer
12-
from pydantic import AnyUrl
12+
from pydantic import AnyUrl, TypeAdapter
1313
from pytest_mock import MockerFixture
1414
from pytest_simcore.helpers.typing_env import EnvVarsDict
1515
from servicelib.rabbitmq import RabbitMQRPCClient
@@ -30,20 +30,17 @@
3030

3131
@pytest.fixture
3232
async def mocked_export(mocker: MockerFixture):
33-
mock_export = mocker.patch(
33+
mocker.patch(
3434
"simcore_service_resource_usage_tracker.services.service_runs.ResourceTrackerRepository.export_service_runs_table_to_s3",
3535
autospec=True,
3636
)
3737

3838

3939
@pytest.fixture
4040
async def mocked_presigned_link(mocker: MockerFixture):
41-
mock_presigned_link = mocker.patch(
41+
mocker.patch(
4242
"simcore_service_resource_usage_tracker.services.service_runs.SimcoreS3API.create_single_presigned_download_link",
43-
return_value=parse_obj_as(
44-
AnyUrl,
45-
"https://www.testing.com/",
46-
),
43+
return_value=TypeAdapter(AnyUrl).validate_python("https://www.testing.com/"),
4744
)
4845

4946

0 commit comments

Comments
 (0)