Skip to content

Commit

Permalink
♻️ Currently frontend is expecting status field in error response b…
Browse files Browse the repository at this point in the history
…ody (#7256)
  • Loading branch information
matusdrobuliak66 authored Feb 21, 2025
1 parent b084481 commit 870b9b2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
14 changes: 10 additions & 4 deletions packages/models-library/src/models_library/rest_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ class ErrorGet(BaseModel):
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(deprecated=True)] = 400
errors: Annotated[
list[ErrorItemType],
Field(deprecated=True, default_factory=list, json_schema_extra={"default": []}),
Expand All @@ -94,11 +94,13 @@ class ErrorGet(BaseModel):
json_schema_extra={
"examples": [
{
"message": "Sorry you do not have sufficient access rights for product"
"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,
},
]
},
Expand All @@ -111,9 +113,13 @@ class EnvelopedError(Envelope[None]):
model_config = ConfigDict(
json_schema_extra={
"examples": [
{"error": {"message": "display error message here"}},
{"error": {"message": "display error message here", "status": 401}},
{
"error": {"message": "failure", "supportId": "OEC:123455"},
"error": {
"message": "failure",
"supportId": "OEC:123455",
"status": 500,
},
"data": None,
},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10021,8 +10021,6 @@ components:
status:
type: integer
title: Status
default: 400
deprecated: true
errors:
items:
$ref: '#/components/schemas/ErrorItemType'
Expand All @@ -10040,6 +10038,7 @@ components:
type: object
required:
- message
- status
title: ErrorGet
ErrorItemType:
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async def _exception_handler(
_DefaultDict(getattr(exception, "__dict__", {}))
)

error = ErrorGet.model_construct(message=user_msg)
error = ErrorGet.model_construct(message=user_msg, status=status_code)

if is_5xx_server_error(status_code):
oec = create_error_code(exception)
Expand All @@ -100,7 +100,9 @@ async def _exception_handler(
},
)
)
error = ErrorGet.model_construct(message=user_msg, support_id=oec)
error = ErrorGet.model_construct(
message=user_msg, support_id=oec, status=status_code
)

return create_error_response(error, status_code=status_code)

Expand Down

0 comments on commit 870b9b2

Please sign in to comment.