Skip to content

Commit dc1b3b3

Browse files
Fixed broken error_notification function
Had been silently failing instead of sending emails on errors like it should have been. Alse: * Removed `the_vars`, which was causing the error (couldn't open the tmp json file), so we won't get the full interview context with the emails (should be okay) * Send that email error notification if the user fails to login for any reason (besides a 403)
1 parent 0f71403 commit dc1b3b3

2 files changed

Lines changed: 12 additions & 34 deletions

File tree

docassemble/EFSPIntegration/conversions.py

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
DAObject,
1313
DADateTime,
1414
as_datetime,
15+
current_context,
1516
validation_error,
1617
log,
1718
as_datetime,
@@ -49,7 +50,7 @@
4950
TypeType = type(type(None))
5051

5152

52-
def error_notification(err, message=None, trace=None, referer=None, the_vars=None):
53+
def error_notification(err, message=None, trace=None, referer=None):
5354
"""Copied from docassemble.webapp.server.error_notification, since:
5455
1) things from webapp.* are unstable
5556
2) it breaks the unit tests and the mypy
@@ -79,31 +80,6 @@ def error_notification(err, message=None, trace=None, referer=None, the_vars=Non
7980
email_address = user_info().email
8081
except:
8182
email_address = None
82-
referer = None
83-
if get_config("error notification variables", get_config("debug", True)):
84-
if the_vars is None:
85-
try:
86-
the_vars = docassemble.base.functions.all_variables(
87-
include_internal=True
88-
)
89-
except:
90-
pass
91-
else:
92-
the_vars = None
93-
json_filename = None
94-
if the_vars is not None and len(the_vars):
95-
try:
96-
with tempfile.NamedTemporaryFile(
97-
mode="w",
98-
prefix="datemp",
99-
suffix=".json",
100-
delete=False,
101-
encoding="utf-8",
102-
) as fp:
103-
fp.write(json.dumps(the_vars, sort_keys=True, indent=2))
104-
json_filename = fp.name
105-
except:
106-
pass
10783
interview_path = docassemble.base.functions.interview_path()
10884
try:
10985
try:
@@ -152,29 +128,28 @@ def error_notification(err, message=None, trace=None, referer=None, the_vars=Non
152128
html += "\n </body>\n</html>"
153129
log(f"Trying to send error message {body}")
154130
send_email(
155-
subject=appname + " error: " + err.__class__.__name,
131+
subject=appname + " error: " + err.__class__.__name__,
156132
to=email_recipients,
157133
body=body,
158134
html=html,
159-
attachments=[json_filename],
160135
)
161136
except Exception as zerr:
162-
log(str(zerr))
137+
log(f"Failed to send original message: {zerr}")
163138
body = "There was an error in the " + appname + " application."
164139
html = (
165140
"<html>\n <body>\n <p>There was an error in the "
166141
+ appname
167142
+ " application.</p>\n </body>\n</html>"
168143
)
169-
log(f"Trying to send error message {body}")
144+
log(f"Trying to send (lesser) error message {body}")
170145
send_email(
171146
subject=appname + " error: " + err.__class__.__name__,
172147
to=email_recipients,
173148
body=body,
174149
html=html,
175-
attachments=[json_filename],
176150
)
177-
except:
151+
except Exception as all_err:
152+
log(f"Big ol err: {all_err}")
178153
pass
179154

180155

@@ -183,7 +158,7 @@ def log_error_and_notify(context: str, resp: Optional[ApiResponse] = None):
183158
the `error_notification_email` in the config."""
184159
message = f"context: {context};; resp: {resp}"
185160
log(f"EFSPIntegration ERROR: {message}")
186-
error_notification(resp, message=message)
161+
error_notification(resp, message=message, referer=current_context().filename)
187162

188163

189164
def convert_court_to_id(trial_court) -> str:

docassemble/EFSPIntegration/data/questions/login_qs.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ code: |
4545
tyler_login_resp = proxy_conn.authenticate_user(tyler_email=my_username, tyler_password=my_password)
4646
del my_password
4747
if not tyler_login_resp.is_ok():
48-
log(f'Failed to login: {tyler_login_resp}')
48+
if int(tyler_login_resp.response_code) != 403:
49+
log_error_and_notify('Failed to login', tyler_login_resp)
50+
else:
51+
log(f'Failed to login: {tyler_login_resp}')
4952
login_failed_screen
5053
else:
5154
log(word("You are now connected to your e-filing account"), "primary")

0 commit comments

Comments
 (0)