|
1 | | -from typing import Any, Dict, Union |
| 1 | +from typing import Any, Dict |
2 | 2 |
|
3 | 3 | from django.conf import settings |
4 | 4 | from django.core.exceptions import ( |
@@ -161,23 +161,21 @@ def db_error(exc, status=500): |
161 | 161 | return cls.build_error_response(500, message) |
162 | 162 |
|
163 | 163 | @staticmethod |
164 | | - def extract_first_error(error_data: Any) -> Union[Any, Dict]: |
| 164 | + def extract_first_error(error_data: Any) -> str: |
165 | 165 | """Extract the first error message from various data structures (dict, |
166 | | - list, string). Stops at the first error encountered. |
| 166 | + list, string). Stops at the first error encountered and returns it as a |
| 167 | + string. |
167 | 168 |
|
168 | | - This method is useful for extracting the first error message from |
169 | | - complex error data structures, such as those returned by Django's |
170 | | - validation framework. |
| 169 | + This method is useful for extracting the first error message from complex error data structures, |
| 170 | + such as those returned by Django's validation framework. |
171 | 171 |
|
172 | 172 | Args: |
173 | | - error_data (Any): The error data structure, which can be a string, |
174 | | - list, or dictionary. |
| 173 | + error_data (Any): The error data structure, which can be a string, list, or dictionary. |
175 | 174 |
|
176 | 175 | Returns: |
177 | | - Union[str, dict]: The extracted error message or structure. If the |
178 | | - input is a list, it returns the first element. If the input is |
179 | | - a dictionary, it returns the first key-value pair. If the input |
180 | | - is a string, it returns the string itself. |
| 176 | + str: The extracted error message as a string. If the input is a list, it processes |
| 177 | + the first element recursively. If the input is a dictionary, it processes |
| 178 | + the first value found. If the input is already a string, it returns the string. |
181 | 179 |
|
182 | 180 | """ |
183 | 181 | if isinstance(error_data, str): |
|
0 commit comments