diff --git a/packages/models-library/src/models_library/rest_error.py b/packages/models-library/src/models_library/rest_error.py index 71cc1b877b66..81631e7b6088 100644 --- a/packages/models-library/src/models_library/rest_error.py +++ b/packages/models-library/src/models_library/rest_error.py @@ -4,6 +4,7 @@ from common_library.basic_types import DEFAULT_FACTORY from models_library.generics import Envelope from pydantic import BaseModel, ConfigDict, Field +from pydantic.config import JsonDict from .basic_types import IDStr, LogLevel @@ -72,39 +73,55 @@ class ErrorGet(BaseModel): description="Message displayed to the user", ), ] + support_id: Annotated[ IDStr | None, Field(description="ID to track the incident during support", alias="supportId"), ] = None - status: int - # NOTE: The fields blow are DEPRECATED. Still here to keep compatibilty with front-end until updated + status: Annotated[ + int, + Field( + description="Redundant HTTP status code of the error." + "Must be the same as in the HTTP response" + ), + ] + + # NOTE: The fields below are DEPRECATED. + # Still here to keep compatibilty with front-end until updated errors: Annotated[ list[ErrorItemType], Field(deprecated=True, default_factory=list, json_schema_extra={"default": []}), ] = DEFAULT_FACTORY + logs: Annotated[ list[LogMessageType], Field(deprecated=True, default_factory=list, json_schema_extra={"default": []}), ] = DEFAULT_FACTORY + @staticmethod + def _update_json_schema_extra(schema: JsonDict) -> None: + schema.update( + { + "examples": [ + { + "message": "Sorry you do not have sufficient access rights for product", + "status": 401, + }, + { + "message": "Opps this error was unexpected. We are working on that!", + "supportId": "OEC:12346789", + "status": 500, + }, + ] + } + ) + model_config = ConfigDict( populate_by_name=True, extra="ignore", # Used to prune extra fields from internal data frozen=True, - json_schema_extra={ - "examples": [ - { - "message": "Sorry you do not have sufficient access rights for product", - "status": 401, - }, - { - "message": "Opps this error was unexpected. We are working on that!", - "supportId": "OEC:12346789", - "status": 500, - }, - ] - }, + json_schema_extra=_update_json_schema_extra, ) diff --git a/services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml b/services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml index 6bdd2034bc97..5c7584f699ba 100644 --- a/services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml +++ b/services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml @@ -11403,6 +11403,8 @@ components: status: type: integer title: Status + description: Redundant HTTP status code of the error.Must be the same as + in the HTTP response errors: items: $ref: '#/components/schemas/ErrorItemType' diff --git a/services/web/server/src/simcore_service_webserver/director_v2/_controller/_rest_exceptions.py b/services/web/server/src/simcore_service_webserver/director_v2/_controller/_rest_exceptions.py index 81f9197fc3c1..b5bb7a6cd7ff 100644 --- a/services/web/server/src/simcore_service_webserver/director_v2/_controller/_rest_exceptions.py +++ b/services/web/server/src/simcore_service_webserver/director_v2/_controller/_rest_exceptions.py @@ -72,7 +72,7 @@ async def _handler_director_service_error_as_503_or_4xx( exception.status ), f"DirectorV2ServiceError must be a client error, got {exception=}" # nosec - error = ErrorGet(status=exception.status, message="{exception}") + error = ErrorGet(status=exception.status, message=f"{exception}") return create_error_response(error, status_code=error.status)