From: Siddharth Mitra Date: Thu, 14 Jul 2011 03:51:55 +0000 (+0800) Subject: Adding exception handling for Value Error: Account already in use, in view.associate_... X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=e4e5f7f63c2c407dbb10725579517ad52cd83992;p=django-social-auth.git Adding exception handling for Value Error: Account already in use, in view.associate_complete --- diff --git a/social_auth/views.py b/social_auth/views.py index b66d3c0..4526545 100644 --- a/social_auth/views.py +++ b/social_auth/views.py @@ -92,8 +92,15 @@ def associate_complete(request, backend): backend = get_backend(backend, request, request.path) if not backend: return HttpResponseServerError('Incorrect authentication service') - backend.auth_complete(user=request.user) - + + try: + backend.auth_complete(user=request.user) + except ValueError, e: # some Authentication error ocurred + user = None + error_key = getattr(settings, 'SOCIAL_AUTH_ERROR_KEY', None) + if error_key: # store error in session + request.session[error_key] = str(e) + url = request.session.pop(REDIRECT_FIELD_NAME, '') or DEFAULT_REDIRECT if NEW_ASSOCIATION_REDIRECT: url = NEW_ASSOCIATION_REDIRECT