Skip to content

Commit 450649f

Browse files
⚡ Update(exceptions) type annotations & docsting to match changes
1 parent e61c903 commit 450649f

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

response_shaper/exceptions.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, Union
1+
from typing import Any, Dict
22

33
from django.conf import settings
44
from django.core.exceptions import (
@@ -161,23 +161,21 @@ def db_error(exc, status=500):
161161
return cls.build_error_response(500, message)
162162

163163
@staticmethod
164-
def extract_first_error(error_data: Any) -> Union[Any, Dict]:
164+
def extract_first_error(error_data: Any) -> str:
165165
"""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.
167168
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.
171171
172172
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.
175174
176175
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.
181179
182180
"""
183181
if isinstance(error_data, str):

0 commit comments

Comments
 (0)