Only send exception mails from production environment

This commit is contained in:
Keith Edmunds 2023-02-18 18:11:19 +00:00
parent a41aea2d36
commit 1c294e1ce4
2 changed files with 7 additions and 5 deletions

View File

@ -76,7 +76,7 @@ def log_uncaught_exceptions(_ex_cls, ex, tb):
logging.critical(''.join(traceback.format_tb(tb))) logging.critical(''.join(traceback.format_tb(tb)))
print("\033[1;37;40m") print("\033[1;37;40m")
print(stackprinter.format(ex, style="darkbg2", add_summary=True)) print(stackprinter.format(ex, style="darkbg2", add_summary=True))
if os.environ["MM_ENV"] != "DEVELOPMENT": if os.environ["MM_ENV"] == "PRODUCTION":
msg = stackprinter.format(ex) msg = stackprinter.format(ex)
send_mail(Config.ERRORS_TO, Config.ERRORS_FROM, send_mail(Config.ERRORS_TO, Config.ERRORS_FROM,
"Exception from musicmuster", msg) "Exception from musicmuster", msg)

View File

@ -3,6 +3,7 @@
from log import log from log import log
from os.path import basename from os.path import basename
import argparse import argparse
import os
import stackprinter # type: ignore import stackprinter # type: ignore
import subprocess import subprocess
import sys import sys
@ -1965,6 +1966,7 @@ if __name__ == "__main__":
engine.dispose() engine.dispose()
sys.exit(status) sys.exit(status)
except Exception as exc: except Exception as exc:
if os.environ["MM_ENV"] == "PRODUCTION":
from helpers import send_mail from helpers import send_mail
msg = stackprinter.format(exc) msg = stackprinter.format(exc)