Skip to content

Commit 5b1b84a

Browse files
authored
🐛 Fixes error message displayed to user coming from director-v2 failure (#7875)
1 parent 90703ba commit 5b1b84a

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

packages/models-library/src/models_library/rest_error.py

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from common_library.basic_types import DEFAULT_FACTORY
55
from models_library.generics import Envelope
66
from pydantic import BaseModel, ConfigDict, Field
7+
from pydantic.config import JsonDict
78

89
from .basic_types import IDStr, LogLevel
910

@@ -72,39 +73,55 @@ class ErrorGet(BaseModel):
7273
description="Message displayed to the user",
7374
),
7475
]
76+
7577
support_id: Annotated[
7678
IDStr | None,
7779
Field(description="ID to track the incident during support", alias="supportId"),
7880
] = None
79-
status: int
8081

81-
# NOTE: The fields blow are DEPRECATED. Still here to keep compatibilty with front-end until updated
82+
status: Annotated[
83+
int,
84+
Field(
85+
description="Redundant HTTP status code of the error."
86+
"Must be the same as in the HTTP response"
87+
),
88+
]
89+
90+
# NOTE: The fields below are DEPRECATED.
91+
# Still here to keep compatibilty with front-end until updated
8292
errors: Annotated[
8393
list[ErrorItemType],
8494
Field(deprecated=True, default_factory=list, json_schema_extra={"default": []}),
8595
] = DEFAULT_FACTORY
96+
8697
logs: Annotated[
8798
list[LogMessageType],
8899
Field(deprecated=True, default_factory=list, json_schema_extra={"default": []}),
89100
] = DEFAULT_FACTORY
90101

102+
@staticmethod
103+
def _update_json_schema_extra(schema: JsonDict) -> None:
104+
schema.update(
105+
{
106+
"examples": [
107+
{
108+
"message": "Sorry you do not have sufficient access rights for product",
109+
"status": 401,
110+
},
111+
{
112+
"message": "Opps this error was unexpected. We are working on that!",
113+
"supportId": "OEC:12346789",
114+
"status": 500,
115+
},
116+
]
117+
}
118+
)
119+
91120
model_config = ConfigDict(
92121
populate_by_name=True,
93122
extra="ignore", # Used to prune extra fields from internal data
94123
frozen=True,
95-
json_schema_extra={
96-
"examples": [
97-
{
98-
"message": "Sorry you do not have sufficient access rights for product",
99-
"status": 401,
100-
},
101-
{
102-
"message": "Opps this error was unexpected. We are working on that!",
103-
"supportId": "OEC:12346789",
104-
"status": 500,
105-
},
106-
]
107-
},
124+
json_schema_extra=_update_json_schema_extra,
108125
)
109126

110127

services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11403,6 +11403,8 @@ components:
1140311403
status:
1140411404
type: integer
1140511405
title: Status
11406+
description: Redundant HTTP status code of the error.Must be the same as
11407+
in the HTTP response
1140611408
errors:
1140711409
items:
1140811410
$ref: '#/components/schemas/ErrorItemType'

services/web/server/src/simcore_service_webserver/director_v2/_controller/_rest_exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async def _handler_director_service_error_as_503_or_4xx(
7272
exception.status
7373
), f"DirectorV2ServiceError must be a client error, got {exception=}" # nosec
7474

75-
error = ErrorGet(status=exception.status, message="{exception}")
75+
error = ErrorGet(status=exception.status, message=f"{exception}")
7676

7777
return create_error_response(error, status_code=error.status)
7878

0 commit comments

Comments
 (0)