Skip to content

Commit

Permalink
WIP: Add more error descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
nyujacky committed Aug 6, 2024
1 parent 22a0017 commit a0aebb6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
18 changes: 5 additions & 13 deletions commerce_coordinator/apps/commercetools/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

from commerce_coordinator.apps.commercetools.catalog_info.constants import DEFAULT_ORDER_EXPANSION, EdXFieldNames
from commerce_coordinator.apps.commercetools.catalog_info.foundational_types import TwoUCustomTypes
from commerce_coordinator.apps.commercetools.utils import translate_stripe_refund_status_to_transaction_status
from commerce_coordinator.apps.commercetools.utils import translate_stripe_refund_status_to_transaction_status, handle_commercetools_error
from commerce_coordinator.apps.core.constants import ORDER_HISTORY_PER_SYSTEM_REQ_LIMIT

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -362,9 +362,7 @@ def create_return_for_order(self, order_id: str, order_version: int, order_line_
)
return returned_order
except CommercetoolsError as err:
logger.error(f"[CommercetoolsError] Unable to create return for "
f"order {order_id} with error correlation id {err.correlation_id} "
f"and error/s: {err.errors}")
handle_commercetools_error(err, f"Unable to create return for order {order_id}")
raise err

def update_return_payment_state_after_successful_refund(self, order_id: str,
Expand Down Expand Up @@ -398,9 +396,7 @@ def update_return_payment_state_after_successful_refund(self, order_id: str,
)
return updated_order
except CommercetoolsError as err:
logger.error(f"[CommercetoolsError] Unable to update ReturnPaymentState "
f"of order {order_id} with error correlation id {err.correlation_id} "
f"and error/s: {err.errors}")
handle_commercetools_error(err, f"Unable to update ReturnPaymentState of order {order_id}")
raise OpenEdxFilterException(str(err)) from err

def create_return_payment_transaction(
Expand Down Expand Up @@ -445,9 +441,7 @@ def create_return_payment_transaction(

return returned_payment
except CommercetoolsError as err:
logger.error(f"[CommercetoolsError] Unable to create refund payment transaction for "
f"payment {payment_id} and stripe refund {stripe_refund.id} with "
f"error correlation id {err.correlation_id} and error/s: {err.errors}")
handle_commercetools_error(err, f"Unable to create refund payment transaction for payment {payment_id}")
raise err

def update_line_item_transition_state_on_fulfillment(self, order_id: str, order_version: int,
Expand Down Expand Up @@ -494,7 +488,5 @@ def update_line_item_transition_state_on_fulfillment(self, order_id: str, order_
return self.get_order_by_id(order_id)
except CommercetoolsError as err:
# Logs & ignores version conflict errors due to duplicate Commercetools messages
logger.error(f"[CommercetoolsError] Unable to update LineItemState "
f"of order {order_id} with error correlation id {err.correlation_id} "
f"and error/s: {err.errors}")
handle_commercetools_error(err, f"Unable to update LineItemState of order {order_id}")
return None
6 changes: 6 additions & 0 deletions commerce_coordinator/apps/commercetools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

import requests
from braze.client import BrazeClient
from commercetools import CommercetoolsError
from commercetools.platform.models import Customer, LineItem, Order, Payment, TransactionState, TransactionType

from django.conf import settings
from django.urls import reverse

Expand All @@ -31,6 +33,10 @@ def get_braze_client():
app_id='',
)

def handle_commercetools_error(err: CommercetoolsError, context: str) -> None:
error_details = [f"Code: {e.code}, Message: {e.message}" for e in err.errors]
error_message = f"[CommercetoolsError] {context} - Correlation ID: {err.correlation_id}, Details: {error_details}"
logger.error(error_message)

def send_order_confirmation_email(
lms_user_id, lms_user_email, canvas_entry_properties
Expand Down

0 comments on commit a0aebb6

Please sign in to comment.