Descend into a nested data structure, forcing any lazy translation strings or strings into `ErrorDetail`.
(data, default_code=None)
| 16 | |
| 17 | |
| 18 | def _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 | |
| 44 | def _get_codes(detail): |