From d094d2f85c3f6d73773820b3135b67b4146a670f Mon Sep 17 00:00:00 2001 From: Vinicius Date: Tue, 20 Feb 2024 19:01:44 -0300 Subject: [PATCH] fix: avoid raise exception in already unsubscribed user --- bd_api/apps/payment/webhooks.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bd_api/apps/payment/webhooks.py b/bd_api/apps/payment/webhooks.py index ab4fb07d..69fd5f49 100644 --- a/bd_api/apps/payment/webhooks.py +++ b/bd_api/apps/payment/webhooks.py @@ -71,15 +71,20 @@ def remove_user(email: str, group_key: str = None) -> None: """Remove user from google group""" if not group_key: group_key = settings.GOOGLE_DIRECTORY_GROUP_KEY + if "+" in email and email.index("+") < email.index("@"): + email = email.split("+")[0] + "@" + email.split("@")[1] try: service = get_service() service.members().delete( groupKey=group_key, memberKey=email, ).execute() - except Exception as e: - logger.error(e) - raise e + except HttpError as e: + if e.resp.status == 404: + logger.warning(f"{email} already unsubscribed") + else: + logger.error(e) + raise e def list_user(group_key: str = None):