error-alert-lite 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.4
2
+ Name: error-alert-lite
3
+ Version: 1.0.0
4
+ Summary: Lightweight Django middleware to automatically email system errors to admins.
5
+ Author: Your Name
6
+ Requires-Dist: Django>=3.0
7
+ Dynamic: author
8
+ Dynamic: requires-dist
9
+ Dynamic: summary
@@ -0,0 +1 @@
1
+ from .middleware import ErrorAlertMiddleware
@@ -0,0 +1,61 @@
1
+ import traceback
2
+ import smtplib
3
+ from email.mime.text import MIMEText
4
+ from email.mime.multipart import MIMEMultipart
5
+ from datetime import datetime, timezone
6
+ from django.conf import settings
7
+
8
+ class ErrorAlertMiddleware:
9
+ def __init__(self, get_response):
10
+ self.get_response = get_response
11
+
12
+ def __call__(self, request):
13
+ # Continue normal normal request processing
14
+ response = self.get_response(request)
15
+ return response
16
+
17
+ def process_exception(self, request, exception):
18
+ # 1. Pull credentials from Django's settings.py
19
+ host = getattr(settings, 'HOST', None)
20
+ port = getattr(settings, 'PORT', 587)
21
+ user = getattr(settings, 'USER', None)
22
+ password = getattr(settings, 'PASS', None)
23
+ admin_email = getattr(settings, 'ADMIN_EMAIL', None)
24
+
25
+ # If credentials are missing, fail silently
26
+ if not all([host, user, password, admin_email]):
27
+ return None
28
+
29
+ # 2. Format the error message
30
+ error_msg = str(exception)
31
+ stack_trace = "".join(traceback.format_tb(exception.__traceback__)) if exception.__traceback__ else "No stack trace"
32
+ time_now = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC")
33
+
34
+ body = f"""
35
+ Route: {request.method} {request.path}
36
+ Time (UTC): {time_now}
37
+
38
+ Error: {error_msg}
39
+
40
+ Stack Trace:
41
+ {stack_trace}
42
+ """
43
+
44
+ # 3. Send the email
45
+ msg = MIMEMultipart()
46
+ msg['From'] = user
47
+ msg['To'] = admin_email
48
+ msg['Subject'] = "🚨 System Error Alert (Django)"
49
+ msg.attach(MIMEText(body, 'plain'))
50
+
51
+ try:
52
+ server = smtplib.SMTP(host, port)
53
+ server.starttls()
54
+ server.login(user, password)
55
+ server.send_message(msg)
56
+ server.quit()
57
+ except Exception as e:
58
+ pass # Fail silently so the app doesn't crash twice
59
+
60
+ # Return None so Django continues its normal error handling (returns a 500 page)
61
+ return None
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.4
2
+ Name: error-alert-lite
3
+ Version: 1.0.0
4
+ Summary: Lightweight Django middleware to automatically email system errors to admins.
5
+ Author: Your Name
6
+ Requires-Dist: Django>=3.0
7
+ Dynamic: author
8
+ Dynamic: requires-dist
9
+ Dynamic: summary
@@ -0,0 +1,8 @@
1
+ setup.py
2
+ error_alert_lite/__init__.py
3
+ error_alert_lite/middleware.py
4
+ error_alert_lite.egg-info/PKG-INFO
5
+ error_alert_lite.egg-info/SOURCES.txt
6
+ error_alert_lite.egg-info/dependency_links.txt
7
+ error_alert_lite.egg-info/requires.txt
8
+ error_alert_lite.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ error_alert_lite
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,10 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name='error-alert-lite',
5
+ version='1.0.0',
6
+ packages=find_packages(),
7
+ description='Lightweight Django middleware to automatically email system errors to admins.',
8
+ author='Your Name',
9
+ install_requires=['Django>=3.0'],
10
+ )