Skip to content

Commit

Permalink
wip (sso): display html message before throw exception
Browse files Browse the repository at this point in the history
  • Loading branch information
vaimdev committed Nov 8, 2024
1 parent 4820620 commit 2d6ad0b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions graphistry/pygraphistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from . import util
from . import bolt_util
from .plotter import Plotter
from .util import in_databricks, setup_logger, in_ipython, make_iframe
from .util import in_databricks, setup_logger, in_ipython, make_iframe, display_message_html
from .exceptions import SsoRetrieveTokenTimeoutException, TokenExpireException

from .messages import (
Expand Down Expand Up @@ -2494,7 +2494,10 @@ def sso_wait_for_token_text_display(repeat: int = 20, wait: int = 5, fail_silent
if not PyGraphistry.sso_repeat_get_token(repeat, wait):
msg_text = f'{msg_text}\nFailed to get token after {repeat*wait} seconds ....'
if not fail_silent:
raise Exception(f"Failed to get token after {repeat*wait} seconds. Please re-run the login process")
msg = f"Failed to get token after {repeat*wait} seconds. Please re-run the login process"
if in_ipython() or in_databricks or PyGraphistry.set_sso_opt_into_type == "display":
display_message_html("<strong>{msg}</strong>")
raise Exception(msg)
else:
msg_text = f'{msg_text}\nGot token'
print(msg_text)
Expand Down
8 changes: 8 additions & 0 deletions graphistry/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ def check_set_memoize(
weakref[hashed] = w
return False

def display_message_html(message: str, cleared: Optional[bool] = False):
from IPython.display import display, HTML, clear_output

if cleared:
clear_output()

display(HTML(message))

def make_iframe_srcdoc(srcdoc: str):
srcdoc = 'srcdoc="{srcdoc}" onload="this.removeAttribute(\'srcdoc\')"'
return srcdoc
Expand Down

0 comments on commit 2d6ad0b

Please sign in to comment.