Modifying TypeError alert when registration by email is cancelled

What I’m trying to do:
I would like to modify Anvil’s somewhat disconcerting alert (see image below) with a simple browser notification like: alert (‘Registration canceled. Please try again.’).

What I’ve tried and what’s not working:

I tried a few codes like:

if usertype ==None:
self.set_account_state(None)
alert ('You cancelled registration. Please try again,')
self.load_component(MainPage())

This doesn’t work as it is obviously way past usertype definition. Is it possible to modify this Anvil alert or if not, just add a more subdued browser alert?

Thank you,

Code Sample:

# this is a formatted code snippet.
# paste your code between ``` 

Clone link:
share a copy of your app

Wherever the error code is, use a try except block and put the alert you want in the except block.

OK. I was thinking about that but not sure how to go about it. Gotta check the python TypeError exception. Thanks.

You might also be eluding to this part of the docs:

1 Like

Yes. I was more concerned about the TypeError alert that shows when running the app. I just wanted to alert the user that it’s not a ‘fatal’ error as may be implied by the alarming red border.

I think I will try the Custom Error Handler option.

Thank you,.

Thank you, @stucork.

Here’s the Custom Error Handler that served my purpose.

def error_handler(self):
    err = 'Dismiss this error and try again.'
    alert(str(err), title="This is a non-fatal TypeError.")
set_default_error_handling(error_handler)

def drop_down_usertype_change(self, **event_args):
    user = anvil.users.signup_with_form(allow_cancel=True)

    if user ==None:
      self.error_handler(err)
      return
 

It’s all well and good. Much thanks :smiling_face_with_three_hearts:.