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.
This commit is contained in:
phot0n 2022-07-01 11:00:06 +05:30
parent 8b38fcb438
commit 5bf26819a8
2 changed files with 7 additions and 6 deletions

View file

@ -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)

View file

@ -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,
)