MCPcopy Index your code
hub / github.com/encode/django-rest-framework / _get_error_details

Function _get_error_details

rest_framework/exceptions.py:18–41  ·  view source on GitHub ↗

Descend into a nested data structure, forcing any lazy translation strings or strings into `ErrorDetail`.

(data, default_code=None)

Source from the content-addressed store, hash-verified

16
17
18def _get_error_details(data, default_code=None):
19 """
20 Descend into a nested data structure, forcing any
21 lazy translation strings or strings into `ErrorDetail`.
22 """
23 if isinstance(data, (list, tuple)):
24 ret = [
25 _get_error_details(item, default_code) for item in data
26 ]
27 if isinstance(data, ReturnList):
28 return ReturnList(ret, serializer=data.serializer)
29 return ret
30 elif isinstance(data, dict):
31 ret = {
32 key: _get_error_details(value, default_code)
33 for key, value in data.items()
34 }
35 if isinstance(data, ReturnDict):
36 return ReturnDict(ret, serializer=data.serializer)
37 return ret
38
39 text = force_str(data)
40 code = getattr(data, 'code', default_code)
41 return ErrorDetail(text, code)
42
43
44def _get_codes(detail):

Callers 3

__init__Method · 0.85
__init__Method · 0.85

Calls 3

ReturnListClass · 0.90
ReturnDictClass · 0.90
ErrorDetailClass · 0.85

Tested by 1