Skip to content

Commit

Permalink
fix: remove redundant error description
Browse files Browse the repository at this point in the history
  • Loading branch information
GareArc committed Dec 26, 2024
1 parent ae0aee5 commit f008c26
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
4 changes: 2 additions & 2 deletions api/controllers/console/auth/forgot_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from constants.languages import languages
from controllers.console import api
from controllers.console.auth.error import EmailCodeError, InvalidEmailError, InvalidTokenError, PasswordMismatchError
from controllers.console.error import AccountNotFound, AccountOnRegisterError, EmailSendIpLimitError
from controllers.console.error import AccountInFreezeError, AccountNotFound, EmailSendIpLimitError
from controllers.console.wraps import setup_required
from events.tenant_event import tenant_was_created
from extensions.ext_database import db
Expand Down Expand Up @@ -126,7 +126,7 @@ def post(self):
except WorkSpaceNotAllowedCreateError:
pass
except AccountRegisterError as are:
raise AccountOnRegisterError(description=are.description)
raise AccountInFreezeError()

return {"result": "success"}

Expand Down
14 changes: 6 additions & 8 deletions api/controllers/console/auth/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
)
from controllers.console.error import (
AccountBannedError,
AccountInFreezeError,
AccountNotFound,
AccountOnRegisterError,
EmailSendIpLimitError,
NotAllowedCreateWorkspace,
)
Expand Down Expand Up @@ -49,9 +49,7 @@ def post(self):
args = parser.parse_args()

if dify_config.BILLING_ENABLED and BillingService.is_email_in_freeze(args["email"]):
raise AccountOnRegisterError(
description="Unable to re-register the account because the deletion occurred less than 30 days ago"
)
raise AccountInFreezeError()

is_login_error_rate_limit = AccountService.is_login_error_rate_limit(args["email"])
if is_login_error_rate_limit:
Expand Down Expand Up @@ -125,7 +123,7 @@ def post(self):
try:
account = AccountService.get_user_through_email(args["email"])
except AccountRegisterError as are:
raise AccountOnRegisterError(description=are.description)
raise AccountInFreezeError()
if account is None:
if FeatureService.get_system_features().is_allow_register:
token = AccountService.send_reset_password_email(email=args["email"], language=language)
Expand Down Expand Up @@ -156,7 +154,7 @@ def post(self):
try:
account = AccountService.get_user_through_email(args["email"])
except AccountRegisterError as are:
raise AccountOnRegisterError(description=are.description)
raise AccountInFreezeError()

if account is None:
if FeatureService.get_system_features().is_allow_register:
Expand Down Expand Up @@ -194,7 +192,7 @@ def post(self):
try:
account = AccountService.get_user_through_email(user_email)
except AccountRegisterError as are:
raise AccountOnRegisterError(description=are.description)
raise AccountInFreezeError()
if account:
tenant = TenantService.get_join_tenants(account)
if not tenant:
Expand All @@ -214,7 +212,7 @@ def post(self):
except WorkSpaceNotAllowedCreateError:
return NotAllowedCreateWorkspace()
except AccountRegisterError as are:
raise AccountOnRegisterError(description=are.description)
raise AccountInFreezeError()
token_pair = AccountService.login(account, ip_address=extract_remote_ip(request))
AccountService.reset_login_error_rate_limit(args["email"])
return {"result": "success", "data": token_pair.model_dump()}
Expand Down
12 changes: 7 additions & 5 deletions api/controllers/console/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ class UnauthorizedAndForceLogout(BaseHTTPException):
description = "Unauthorized and force logout."
code = 401


class AccountOnRegisterError(BaseHTTPException):
error_code = "account_register_error"
code = 400
description = "Account register error."
class AccountInFreezeError(BaseHTTPException):
error_code = "account_in_freeze"
code = 400
description = (
"This email account has been deleted within the past 30 days"
"and is temporarily unavailable for new account registration."
)
10 changes: 8 additions & 2 deletions api/services/account_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,10 @@ def create_account(

if dify_config.BILLING_ENABLED and BillingService.is_email_in_freeze(email):
raise AccountRegisterError(
description="Unable to re-register the account because the deletion occurred less than 30 days ago"
description=(
"This email account has been deleted within the past "
"30 days and is temporarily unavailable for new account registration"
)
)

account = Account()
Expand Down Expand Up @@ -459,7 +462,10 @@ def revoke_email_code_login_token(cls, token: str):
def get_user_through_email(cls, email: str):
if dify_config.BILLING_ENABLED and BillingService.is_email_in_freeze(email):
raise AccountRegisterError(
description="Unable to re-register the account because the deletion occurred less than 30 days ago"
description=(
"This email account has been deleted within the past "
"30 days and is temporarily unavailable for new account registration"
)
)

account = db.session.query(Account).filter(Account.email == email).first()
Expand Down

0 comments on commit f008c26

Please sign in to comment.