on-internet
← Community

In Django REST Framework, why does raising serializers.ValidationError return errors in different format in validate() and create() methods?

Stack Overflow ·

I am working on a DRF project and have a serializer like: class SomeSerializer(serializers.Serializer): number_field = serializers.IntegerField(required=False, min_value=25, max_value=100) In my settings.py, I have REST_FRAMEWORK = { other settings.... 'EXCEPTION_HANDLER': 'apps.utils.exceptions.custom_exception_handler', } In the custom exception handler, I handle ValidationError as follows: def custom_exception_handler(exc, context): # Call REST framework's default exception handler first response = exception_handler(exc, context) messages = None code = None detail = None if response is not

Comments

Sign in or sign up to comment and upvote.

No comments yet.