MCPcopy
hub / github.com/encode/django-rest-framework / get_error_detail

Function get_error_detail

rest_framework/fields.py:213–233  ·  view source on GitHub ↗

Given a Django ValidationError, return a list of ErrorDetail, with the `code` populated.

(exc_info)

Source from the content-addressed store, hash-verified

211
212
213def get_error_detail(exc_info):
214 """
215 Given a Django ValidationError, return a list of ErrorDetail,
216 with the `code` populated.
217 """
218 code = getattr(exc_info, 'code', None) or 'invalid'
219
220 try:
221 error_dict = exc_info.error_dict
222 except AttributeError:
223 return [
224 ErrorDetail((error.message % error.params) if error.params else error.message,
225 code=error.code if error.code else code)
226 for error in exc_info.error_list]
227 return {
228 k: [
229 ErrorDetail((error.message % error.params) if error.params else error.message,
230 code=error.code if error.code else code)
231 for error in errors
232 ] for k, errors in error_dict.items()
233 }
234
235
236class CreateOnlyDefault:

Callers 4

as_serializer_errorFunction · 0.90
to_internal_valueMethod · 0.90
run_validatorsMethod · 0.85
run_child_validationMethod · 0.85

Calls 1

ErrorDetailClass · 0.90

Tested by

no test coverage detected