|
4 | 4 | from common_library.basic_types import DEFAULT_FACTORY |
5 | 5 | from models_library.generics import Envelope |
6 | 6 | from pydantic import BaseModel, ConfigDict, Field |
| 7 | +from pydantic.config import JsonDict |
7 | 8 |
|
8 | 9 | from .basic_types import IDStr, LogLevel |
9 | 10 |
|
@@ -72,39 +73,55 @@ class ErrorGet(BaseModel): |
72 | 73 | description="Message displayed to the user", |
73 | 74 | ), |
74 | 75 | ] |
| 76 | + |
75 | 77 | support_id: Annotated[ |
76 | 78 | IDStr | None, |
77 | 79 | Field(description="ID to track the incident during support", alias="supportId"), |
78 | 80 | ] = None |
79 | | - status: int |
80 | 81 |
|
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 |
82 | 92 | errors: Annotated[ |
83 | 93 | list[ErrorItemType], |
84 | 94 | Field(deprecated=True, default_factory=list, json_schema_extra={"default": []}), |
85 | 95 | ] = DEFAULT_FACTORY |
| 96 | + |
86 | 97 | logs: Annotated[ |
87 | 98 | list[LogMessageType], |
88 | 99 | Field(deprecated=True, default_factory=list, json_schema_extra={"default": []}), |
89 | 100 | ] = DEFAULT_FACTORY |
90 | 101 |
|
| 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 | + |
91 | 120 | model_config = ConfigDict( |
92 | 121 | populate_by_name=True, |
93 | 122 | extra="ignore", # Used to prune extra fields from internal data |
94 | 123 | 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, |
108 | 125 | ) |
109 | 126 |
|
110 | 127 |
|
|
0 commit comments