[ErrorDetail(string='This field is required.', code='required')]
How get code from this object. I want separate error code for custom error response, i tried many solutions but i didn't get any working answer.
I found myself wanting to read the string field of the Error.
So for an error like:
<Response status_code=400, "application/json">
{'field_name': [ErrorDetail(string='the error message', code='invalid')]}
To get the string (e.g. for testing), I've used:
self.assertEqual(str(response.data['field_name'][0]), 'the error message')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With