From 3e449a9d64430315b4989cba1f77aa5ae0ceb823 Mon Sep 17 00:00:00 2001 From: Piotr Zalewa Date: Thu, 8 Mar 2012 11:02:46 +0100 Subject: [PATCH] try to fetch user with API, fall back to SQL --- apps/amo/authentication.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/apps/amo/authentication.py b/apps/amo/authentication.py index 8ac0f538..0cd3ac73 100644 --- a/apps/amo/authentication.py +++ b/apps/amo/authentication.py @@ -1,7 +1,10 @@ import hashlib import commonware +import traceback +import sys from django.contrib.auth.models import User +from django.core.mail import mail_admins from django.utils.encoding import smart_str from django.conf import settings @@ -120,7 +123,16 @@ class AMOAuthentication: port=settings.AMOOAUTH_PORT, protocol=settings.AMOOAUTH_PROTOCOL, prefix=settings.AMOOAUTH_PREFIX) - return amo.get_user_by_email(email) or None + try: + return amo.get_user_by_email(email) or None + except: + exc_type, exc_value, exc_traceback = sys.exc_info() + tb = traceback.format_exception(exc_type, exc_value, exc_traceback) + mail_admins( + '[Django] ERROR: Unknown error in AMOOauth', + "Might be an issue with OAuth in -dev\n %s" % tb) + + return AMOAuthentication.fetch_amo_user_old(email) @staticmethod def fetch_amo_user_old(email):