|
|
@@ -822,8 +822,17 @@ async def stripe_webhook(request: Request, background_tasks: BackgroundTasks):
|
|
|
"block_types": settings.block_types,
|
|
|
}
|
|
|
|
|
|
- order = prepare_email_order(order_id, email_settings)
|
|
|
- await send_email(email_settings, order, background_tasks)
|
|
|
+ # It's possible the order was just created and not all data is available yet
|
|
|
+ # The prepare_email_order function should handle this gracefully
|
|
|
+ try:
|
|
|
+ order = prepare_email_order(order_id, email_settings)
|
|
|
+ await send_email(email_settings, order, background_tasks)
|
|
|
+
|
|
|
+ except TypeError as e:
|
|
|
+ # Specifically catch the 'NoneType' object is not iterable error
|
|
|
+ main_logger.warning(f"stripe-webhook warning: Email preparation issue, possibly due to timing: {e}")
|
|
|
+ # Consider implementing a retry mechanism here if needed
|
|
|
+ # For example, add the email task to a queue to try again later
|
|
|
|
|
|
except Exception as e:
|
|
|
main_logger.error(f"stripe-webhook error: Failed to send email: {e}")
|
|
|
@@ -998,22 +1007,46 @@ async def now_webhook(request: Request, background_tasks: BackgroundTasks):
|
|
|
|
|
|
if product_list:
|
|
|
for product_info in product_list:
|
|
|
- update_product_inventory(
|
|
|
- product_info.filename,
|
|
|
- product_info.quantity,
|
|
|
- product_info.product_variation_id,
|
|
|
- settings,
|
|
|
- )
|
|
|
+ try:
|
|
|
+ product = read_file(
|
|
|
+ settings.git_repo,
|
|
|
+ f"products/{product_info.filename}",
|
|
|
+ settings.document_match,
|
|
|
+ settings.block_types,
|
|
|
+ )
|
|
|
+
|
|
|
+ # Get the variation ID based on size and style
|
|
|
+ product_variation_id = get_variation_id(product,
|
|
|
+ product_info.size,
|
|
|
+ product_info.style)
|
|
|
+
|
|
|
+ update_product_inventory(
|
|
|
+ product_info.filename,
|
|
|
+ product_info.quantity,
|
|
|
+ product_variation_id,
|
|
|
+ settings,
|
|
|
+ )
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ main_logger.error(f"now-webhook error: Failed to update inventory: {e}")
|
|
|
+ # Continue processing other products
|
|
|
|
|
|
# -- send email
|
|
|
- email_settings = {
|
|
|
- "git_repo": settings.git_repo,
|
|
|
- "document_match": settings.document_match,
|
|
|
- "block_types": settings.block_types,
|
|
|
- }
|
|
|
-
|
|
|
- order = prepare_email_order(order_id, email_settings)
|
|
|
- await send_email(email_settings, order, background_tasks)
|
|
|
+ try:
|
|
|
+ email_settings = {
|
|
|
+ "git_repo": settings.git_repo,
|
|
|
+ "document_match": settings.document_match,
|
|
|
+ "block_types": settings.block_types,
|
|
|
+ }
|
|
|
+
|
|
|
+ try:
|
|
|
+ order = prepare_email_order(order_id, email_settings)
|
|
|
+ await send_email(email_settings, order, background_tasks)
|
|
|
+ except TypeError as e:
|
|
|
+ main_logger.warning(f"now-webhook warning: Email preparation issue: {e}")
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ main_logger.error(f"now-webhook error: Failed to send email: {e}")
|
|
|
|
|
|
elif event_type == "failed":
|
|
|
main_logger.error(
|