- Create a utils function called
render_page which wraps an entire page in a try-except clause
- Each page's code needs to wrapped in a
main() function for this to work
- Upon an exception, we can log the error to runtime logs but also run a Slack alert
See example snippets to incorporate into the codebase:
def render_page(page_func):
try:
page_func()
except Exception as e:
logging.error(e)
send_slack_alert(str(e))
st.error("Something went wrong loading the data. Please try again later.")
st.stop()
and
def main():
# for each page, move all page logic here
df = load_data()
st.dataframe(df)
render_page(main)
render_pagewhich wraps an entire page in a try-except clausemain()function for this to workSee example snippets to incorporate into the codebase:
and