1👍
✅
Handling exceptions based on the Validation Error message might be a bit of an anti-pattern, and you might regret going down that road. One way around this is to check the conditions that raise the exceptions – before it becomes in an exception.
I don’t have any details of your app, but another option would be to override the ‘validate’ method in rest_auth serializer. This would allow you to check the for the condition first (before rest_auth) and handle it however you want. The nice thing about this projects is that they are open source, and you can view the source to see how it raises this error.
class SpecialValidator(LoginSerializer):
def validate(self, attrs):
username = attrs.get('username')
email_address = user.emailaddress_set.get(email=user.email)
if not email_address.verified:
# This is where you put in your special handling
return super(SpecialValidator, self).validate(attrs)
Source:stackexchange.com