Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 32 additions & 15 deletions packages/models-library/src/models_library/rest_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading