From 5bf26819a8d44dd3619f35aa8011104ee87f616d Mon Sep 17 00:00:00 2001 From: phot0n Date: Fri, 1 Jul 2022 11:00:06 +0530 Subject: [PATCH] fix: better/reduced exception handling for email oauth Since the places where connection methods are called already have a lot of exception handling, we can just raise and let them handle all the probable cases. --- frappe/email/oauth.py | 11 ++++++----- frappe/email/smtp.py | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/frappe/email/oauth.py b/frappe/email/oauth.py index cebb370b1f..9d456daf81 100644 --- a/frappe/email/oauth.py +++ b/frappe/email/oauth.py @@ -63,16 +63,17 @@ class Oauth: # SMTP self._connect_smtp() - except Exception: + except Exception as e: # maybe the access token expired - refreshing access_token = self._refresh_access_token() if not access_token or _retry > 0: - frappe.throw( - frappe._("Authentication Failed. Please Check and Update the credentials."), - OAuthenticationError, - frappe._("OAuth Error"), + frappe.log_error( + "OAuth Error - Authentication Failed", str(e), "Email Account", self.email_account ) + # raising a bare exception here as we have a lot of exception handling present + # where the connect method is called from - hence just logging and raising. + raise self._access_token = access_token self.connect(_retry + 1) diff --git a/frappe/email/smtp.py b/frappe/email/smtp.py index 687b8318b6..10eb2f7681 100644 --- a/frappe/email/smtp.py +++ b/frappe/email/smtp.py @@ -147,7 +147,7 @@ class SMTPServer: @classmethod def throw_invalid_credentials_exception(cls): frappe.throw( - _("Incorrect email or password. Please check your login credentials."), + _("Please check your email login credentials."), title=_("Invalid Credentials"), exc=InvalidEmailCredentials, )