Skip to content

Commit 89bdc4b

Browse files
committed
error handling
1 parent c92c20c commit 89bdc4b

File tree

6 files changed

+48
-12
lines changed

6 files changed

+48
-12
lines changed

packages/common-library/src/common_library/errors_classes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def make_resource_error(
6666
resource: str,
6767
error_cls: type[OsparcErrorMixin],
6868
base_exception: type[Exception] = Exception,
69-
) -> type[OsparcErrorMixin]:
69+
) -> type[Exception]:
7070
class _ResourceError(error_cls, base_exception):
7171
def __init__(self, **ctx: Any):
7272
ctx.setdefault("resource", resource)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from common_library.errors_classes import (
2+
OsparcErrorMixin,
3+
)
4+
5+
6+
class WebServerRpcError(OsparcErrorMixin, Exception):
7+
msg_template = "{details}"
8+
9+
@classmethod
10+
def from_domain_error(cls, err: OsparcErrorMixin):
11+
return cls(details=f"{err} [{err.__class__.__name__}]", **err.error_context())
12+
13+
14+
class ProjectNotFoundRpcError(WebServerRpcError): ...
15+
16+
17+
class ProjectForbiddenRpcError(WebServerRpcError): ...

packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/webserver/projects.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ async def mark_project_as_job(
3434
user_id=user_id,
3535
project_uuid=project_uuid,
3636
job_parent_resource_name=job_parent_resource_name,
37+
timeout_s=None, # TODO: remove after testing
3738
)
3839
assert result is None

services/web/server/src/simcore_service_webserver/projects/_controller/projects_rpc.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,27 @@
33
from models_library.products import ProductName
44
from models_library.projects import ProjectID
55
from models_library.users import UserID
6-
from pydantic import validate_call
6+
from pydantic import ValidationError, validate_call
77
from servicelib.rabbitmq import RPCRouter
8+
from servicelib.rabbitmq.rpc_interfaces.webserver.errors import (
9+
ProjectForbiddenRpcError,
10+
ProjectNotFoundRpcError,
11+
)
812

913
from ...rabbitmq import get_rabbitmq_rpc_server
1014
from .. import _jobs_service
15+
from ..exceptions import ProjectInvalidRightsError
1116

1217
router = RPCRouter()
1318

1419

15-
@router.expose()
20+
@router.expose(
21+
reraise_if_error_type=(
22+
ProjectForbiddenRpcError,
23+
ProjectNotFoundRpcError,
24+
ValidationError,
25+
)
26+
)
1627
@validate_call(config={"arbitrary_types_allowed": True})
1728
async def mark_project_as_job(
1829
app: web.Application,
@@ -23,13 +34,17 @@ async def mark_project_as_job(
2334
job_parent_resource_name: str,
2435
) -> None:
2536

26-
await _jobs_service.set_project_as_job(
27-
app,
28-
product_name=product_name,
29-
user_id=user_id,
30-
project_uuid=project_uuid,
31-
job_parent_resource_name=job_parent_resource_name,
32-
)
37+
try:
38+
39+
await _jobs_service.set_project_as_job(
40+
app,
41+
product_name=product_name,
42+
user_id=user_id,
43+
project_uuid=project_uuid,
44+
job_parent_resource_name=job_parent_resource_name,
45+
)
46+
except ProjectInvalidRightsError as err:
47+
raise ProjectForbiddenRpcError.from_domain_error(err) from err
3348

3449

3550
async def register_rpc_routes_on_startup(app: web.Application):

services/web/server/src/simcore_service_webserver/projects/_jobs_repository.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async def set_project_as_job(
2424
stmt = (
2525
pg_insert(projects_to_jobs)
2626
.values(
27-
project_uuid=project_uuid,
27+
project_uuid=f"{project_uuid}",
2828
job_parent_resource_name=job_parent_resource_name,
2929
)
3030
.on_conflict_do_update(

services/web/server/tests/unit/with_dbs/02/test_projects_rpc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from pytest_simcore.helpers.webserver_login import NewUser, UserInfoDict
1818
from servicelib.rabbitmq import RabbitMQRPCClient
1919
from servicelib.rabbitmq.rpc_interfaces.webserver import projects as projects_rpc
20+
from servicelib.rabbitmq.rpc_interfaces.webserver.errors import ProjectForbiddenRpcError
2021
from settings_library.rabbit import RabbitSettings
2122
from simcore_service_webserver.application_settings import ApplicationSettings
2223
from simcore_service_webserver.projects.models import ProjectDict
@@ -101,7 +102,7 @@ async def test_rpc_client_mark_project_as_job(
101102
job_parent_resource_name="solvers/solver123/version/1.2.3",
102103
)
103104

104-
with pytest.raises(Exception, match="no access"):
105+
with pytest.raises(ProjectForbiddenRpcError) as err_info:
105106
await projects_rpc.mark_project_as_job(
106107
rpc_client=rpc_client,
107108
product_name=product_name,
@@ -110,6 +111,8 @@ async def test_rpc_client_mark_project_as_job(
110111
job_parent_resource_name="solvers/solver123/version/1.2.3",
111112
)
112113

114+
assert err_info.value.error_context()["project_uuid"] == project_uuid
115+
113116
with pytest.raises(Exception, match="not found"):
114117
await projects_rpc.mark_project_as_job(
115118
rpc_client=rpc_client,

0 commit comments

Comments
 (0)