Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exception handler draft #1

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions reflex/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,6 @@ def _callback_arg_spec(eval_result):
def call_script(
javascript_code: str,
callback: EventHandler | Callable | None = None,
exception_handler: callable | None = None
) -> EventSpec:
"""Create an event handler that executes arbitrary javascript code.

Expand All @@ -668,19 +667,23 @@ def call_script(
callback_kwargs = {
"callback": f"({arg_name}) => queueEvents([{format.format_event(event_spec)}], {constants.CompileVars.SOCKET})"
}
wrapped_code = f"""

This comment was marked as resolved.

try {{
{javascript_code}
}} catch (error) {{
queueEvents([{window_alert("'An error occurred. See logs for details.'")}], {constants.CompileVars.SOCKET});
}}
"""


try:
return server_side(

return server_side(
"_call_script",
get_fn_signature(call_script),
javascript_code=javascript_code,
javascript_code=wrapped_code,
**callback_kwargs,
)
except Exception as client_error:
if exception_handler and callable(exception_handler):
exception_handler(client_error)
else:
raise client_error



def get_event(state, event):
Expand Down