This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git


The following commit(s) were added to refs/heads/develop by this push:
     new a80e4c70 Make sure request info gets into error emails
a80e4c70 is described below

commit a80e4c70e99efb127114be38048478197c745293
Author: Marcus Christie <[email protected]>
AuthorDate: Fri Oct 28 16:15:59 2022 -0400

    Make sure request info gets into error emails
---
 django_airavata/apps/api/exceptions.py |  4 ++--
 django_airavata/apps/api/views.py      |  2 +-
 django_airavata/apps/auth/views.py     | 17 +++++++++--------
 3 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/django_airavata/apps/api/exceptions.py 
b/django_airavata/apps/api/exceptions.py
index 0676c126..f9f56592 100644
--- a/django_airavata/apps/api/exceptions.py
+++ b/django_airavata/apps/api/exceptions.py
@@ -33,7 +33,7 @@ def custom_exception_handler(exc, context):
     # Default TException handler, should come after more specific subclasses of
     # TException
     if isinstance(exc, TException):
-        log.error("TException", exc_info=exc)
+        log.error("TException", exc_info=exc, extra={'request': 
context['request']})
         return Response(
             {'detail': str(exc)},
             status=status.HTTP_500_INTERNAL_SERVER_ERROR)
@@ -51,7 +51,7 @@ def custom_exception_handler(exc, context):
 
     # Generic handler
     if response is None:
-        log.error("API exception", exc_info=exc)
+        log.error("API exception", exc_info=exc, extra={'request': 
context['request']})
         return Response(
             {'detail': str(exc)},
             status=status.HTTP_500_INTERNAL_SERVER_ERROR
diff --git a/django_airavata/apps/api/views.py 
b/django_airavata/apps/api/views.py
index 75fe425e..b419a14e 100644
--- a/django_airavata/apps/api/views.py
+++ b/django_airavata/apps/api/views.py
@@ -847,7 +847,7 @@ def upload_input_file(request):
         return JsonResponse({'uploaded': True,
                              'data-product': serializer.data})
     except Exception as e:
-        log.error("Failed to upload file", exc_info=True)
+        log.error("Failed to upload file", exc_info=True, extra={'request': 
request})
         resp = JsonResponse({'uploaded': False, 'error': str(e)})
         resp.status_code = 500
         return resp
diff --git a/django_airavata/apps/auth/views.py 
b/django_airavata/apps/auth/views.py
index 0f93678b..1c7cf6a5 100644
--- a/django_airavata/apps/auth/views.py
+++ b/django_airavata/apps/auth/views.py
@@ -130,7 +130,7 @@ def handle_login(request):
         else:
             messages.error(request, "Login failed. Please try again.")
     except Exception as err:
-        logger.exception("Login failed for user {}".format(username))
+        logger.exception("Login failed for user {}".format(username), 
extra={'request': request})
         messages.error(request,
                        "Login failed: {}. Please try again.".format(str(err)))
     if login_desktop:
@@ -169,7 +169,8 @@ def callback(request):
             raise Exception("Failed to authenticate user")
     except Exception as err:
         logger.exception("An error occurred while processing OAuth2 "
-                         "callback: {}".format(request.build_absolute_uri()))
+                         "callback: {}".format(request.build_absolute_uri()),
+                         extra={'request': request})
         messages.error(
             request,
             "Failed to process OAuth2 callback: {}".format(str(err)))
@@ -226,7 +227,7 @@ def create_account(request):
                         reverse('django_airavata_auth:create_account'))
             except Exception as e:
                 logger.exception(
-                    "Failed to create account for user", exc_info=e)
+                    "Failed to create account for user", exc_info=e, 
extra={'request', request})
                 form.add_error(None, ValidationError(e.message))
     else:
         form = forms.CreateAccountForm(initial=request.GET)
@@ -278,14 +279,14 @@ def verify_email(request, code):
         # if doesn't exist, give user a form where they can enter their
         # username to resend verification code
         logger.exception("EmailVerification object doesn't exist for "
-                         "code {}".format(code))
+                         "code {}".format(code), extra={'request': request})
         messages.error(
             request,
             "Email verification failed. Please enter your username and we "
             "will send you another email verification link.")
         return redirect(reverse('django_airavata_auth:resend_email_link'))
     except Exception:
-        logger.exception("Email verification processing failed!")
+        logger.exception("Email verification processing failed!", 
extra={'request': request})
         messages.error(
             request,
             "Email verification failed. Please try clicking the email "
@@ -324,7 +325,7 @@ def resend_email_link(request):
                     reverse('django_airavata_auth:resend_email_link'))
             except Exception as e:
                 logger.exception(
-                    "Failed to resend email verification link", exc_info=e)
+                    "Failed to resend email verification link", exc_info=e, 
extra={'request': request})
                 form.add_error(None, ValidationError(str(e)))
     else:
         form = forms.ResendEmailVerificationLinkForm()
@@ -392,7 +393,7 @@ def forgot_password(request):
             except Exception as e:
                 logger.exception(
                     "Failed to generate password reset request for user",
-                    exc_info=e)
+                    exc_info=e, extra={'request': request})
                 form.add_error(None, ValidationError(str(e)))
     else:
         form = forms.ForgotPasswordForm()
@@ -464,7 +465,7 @@ def reset_password(request, code):
                         reverse('django_airavata_auth:login_with_password'))
             except Exception as e:
                 logger.exception(
-                    "Failed to reset password for user", exc_info=e)
+                    "Failed to reset password for user", exc_info=e, 
extra={'request': request})
                 form.add_error(None, ValidationError(str(e)))
     else:
         form = forms.ResetPasswordForm()

Reply via email to