refactor: Replace direct logger.error calls with capture_and_log in accounts services and conditionally pass error_id during ApplicationError creation.

This commit is contained in:
pacnpal
2026-01-04 18:36:23 -05:00
parent 95700c7d7b
commit bc4a3c7557
6 changed files with 40 additions and 27 deletions

View File

@@ -17,6 +17,7 @@ from django.utils import timezone
from django_forwardemail.services import EmailService
from apps.accounts.models import NotificationPreference, User, UserNotification
from apps.core.utils import capture_and_log
logger = logging.getLogger(__name__)
@@ -264,7 +265,7 @@ class NotificationService:
logger.info(f"Email notification sent to {user.email} for notification {notification.id}")
except Exception as e:
logger.error(f"Failed to send email notification {notification.id}: {str(e)}")
capture_and_log(e, f'Send email notification {notification.id}', source='service')
@staticmethod
def get_user_notifications(

View File

@@ -20,6 +20,8 @@ if TYPE_CHECKING:
else:
User = get_user_model()
from apps.core.utils import capture_and_log
logger = logging.getLogger(__name__)
@@ -62,7 +64,7 @@ class SocialProviderService:
return True, "Provider can be safely disconnected."
except Exception as e:
logger.error(f"Error checking disconnect permission for user {user.id}, provider {provider}: {e}")
capture_and_log(e, f'Check disconnect permission for user {user.id}, provider {provider}', source='service')
return False, "Unable to verify disconnection safety. Please try again."
@staticmethod
@@ -97,7 +99,7 @@ class SocialProviderService:
return connected_providers
except Exception as e:
logger.error(f"Error getting connected providers for user {user.id}: {e}")
capture_and_log(e, f'Get connected providers for user {user.id}', source='service')
return []
@staticmethod
@@ -140,7 +142,7 @@ class SocialProviderService:
return available_providers
except Exception as e:
logger.error(f"Error getting available providers: {e}")
capture_and_log(e, 'Get available providers', source='service')
return []
@staticmethod
@@ -177,7 +179,7 @@ class SocialProviderService:
return True, f"{provider.title()} account disconnected successfully."
except Exception as e:
logger.error(f"Error disconnecting {provider} for user {user.id}: {e}")
capture_and_log(e, f'Disconnect {provider} for user {user.id}', source='service')
return False, f"Failed to disconnect {provider} account. Please try again."
@staticmethod
@@ -210,7 +212,7 @@ class SocialProviderService:
}
except Exception as e:
logger.error(f"Error getting auth status for user {user.id}: {e}")
capture_and_log(e, f'Get auth status for user {user.id}', source='service')
return {"error": "Unable to retrieve authentication status"}
@staticmethod
@@ -236,5 +238,5 @@ class SocialProviderService:
return True, f"Provider '{provider}' is valid and available."
except Exception as e:
logger.error(f"Error validating provider {provider}: {e}")
capture_and_log(e, f'Validate provider {provider}', source='service')
return False, "Unable to validate provider."

View File

@@ -18,6 +18,8 @@ from django.db import transaction
from django.template.loader import render_to_string
from django.utils import timezone
from apps.core.utils import capture_and_log
logger = logging.getLogger(__name__)
User = get_user_model()
@@ -292,5 +294,5 @@ class UserDeletionService:
logger.info(f"Deletion verification email sent to {user.email}")
except Exception as e:
logger.error(f"Failed to send deletion verification email to {user.email}: {str(e)}")
capture_and_log(e, f'Send deletion verification email to {user.email}', source='service')
raise