Reputation: 21
I'm using the django-rest-passwordreset
package to implement password reset endpoints.
When a given email doesn't exist, it throws a ValidationError
exception, causing a 500 error. How can I catch this error, and return a 400 instead? I simply added the urls as shown below, so I don't think I can surround it with an try: except
or something similar.
urlpatterns=[
...
url(r'^password/recover/', include('django_rest_passwordreset.urls')),
... ]
Exception:
ValidationError at /password/recover/ {'email': ['There is no active user associated with this e-mail address or the password can not be changed']}
Request Method: POST Request URL: http://192.168.99.100:8000/password/recover/
Django Version: 2.0.6
Traceback:
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner 35. response = get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response 128. response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response 126. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.6/site-packages/django/views/decorators/csrf.py" in wrapped_view 54. return view_func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py" in view 69. return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py" in dispatch 483. response = self.handle_exception(exc)
File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py" in handle_exception 443. self.raise_uncaught_exception(exc)
File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py" in dispatch 480. response = handler(request, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django_rest_passwordreset/views.py" in post 116. code='invalid')}
Exception Type: ValidationError at /password/recover/ Exception Value: {'email': ['There is no active user associated with this e-mail address or the password can not be changed']}
Request information:
USER: AnonymousUser
GET: No GET data
POST: No POST data
FILES: No FILES data
COOKIES: No cookie data
HEADERS: "email" : "bob@thebuilder.com"
Upvotes: 1
Views: 1718