Skip to content

Commit e3d1164

Browse files
Actually notify errors (#270)
`error_notification`, the function called from `log_error_and_notify` that sends an email to the docassemble error email in the config, had been broken, silently, since nothing was logging in the `try: except` blocks. Started logging those issues, and fixed them locally. Also: * 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) * Replaced the `bad_fees` screen with our standard bug screen. That's one of the few screens that's a hard block on E-filing interviews, and is more confusing to users than otherwise. It's better to just say "something went wrong" and give them their options (should make sure they're able to download their forms at that point, but that's a separate thing).
1 parent dad38ed commit e3d1164

3 files changed

Lines changed: 13 additions & 44 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/efiling_integration.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -892,15 +892,6 @@ subquestion: |
892892
There are no fees associated with this filing.
893893
continue button field: review_fees_screen
894894
---
895-
id: bad fees
896-
event: bad_fees
897-
question: |
898-
Something went wrong
899-
subquestion: |
900-
Sorry, something went wrong when trying to figure out if you have to pay fees.
901-
902-
More details: ${ debug_display(fees_resp) }
903-
---
904895
depends on:
905896
- fees_resp
906897
code: |
@@ -940,7 +931,7 @@ code: |
940931
if fees_resp.is_ok():
941932
review_fees_screen
942933
else:
943-
bad_fees
934+
raise Exception(f"Was not able to calculate fees: {fees_resp}")
944935
review_fees = True
945936
---
946937
#############################

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)