How can django-rest return a serializer error in the correct format for the frontend?

Viewed 91

I don't like how django-rest returns a serialization erros JSON. For instance, if two fields are not provided in the request body, the default JSON response is the following:

{
"title": [
    "This field is required."
],
"contract_recipients_data": [
    "This field is required."
]

}

I have read about custom exception handling, but I am not sure how can I flatten this error response. I would like for the error message to contain only a string so that my frontend app can handle it better ( how can the frontend handle this dynamic JSON? It seems difficult and not scalable).

0 Answers
Related