Код: Выделить всё
{
"detail": "Given token not valid for any token type",
"code": "token_not_valid",
"messages": [
{
"token_class": "AccessToken",
"token_type": "access",
"message": "Token is invalid or expired"
}
]
}
Код: Выделить всё
{
"status": false,
"responseCode": 0,
"message": "Validation ",
"data": {}
}
Код: Выделить всё
def custom_exception_handler(exc, context):
response = exception_handler(exc, context)
if response is not None:
custom_response_data = {
'status': False,
'responseCode': 0,
'message': 'Validation error',
'data': {}
}
if isinstance(response.data, dict):
errors = {}
for field, detail in response.data.items():
if isinstance(detail, list):
errors[field] = detail[0] if detail else 'Invalid input.'
elif isinstance(detail, dict):
errors[field] = " | ".join(str(v) for v in detail.values())
else:
errors[field] = str(detail)
custom_response_data['message'] = " | ".join(errors.values())
custom_response_data['data'] = errors
response.data = custom_response_data
return response
Подробнее здесь: https://stackoverflow.com/questions/790 ... -framework