Bypass/Ignore Error Handling?

I have an Anvil form that posts to a Google Form behind the scenes using the auto-submit url format.

I’m using anvil.http.request in Client side to send the link to Google. This works as intended (i.e. Google successfully receives/processes the link). However, this http request interaction with Google throws a HTTP Error 0 and stops the rest of my code in the Anvil form from executing.

Is there any way to suppress error responses when using anvil.http.request? I tried using the set_default_error_handling option described in the Anvil documentation that I have included below. I see how the error_handler can be used to make the presentation of the error prettier for the user. However, I’m looking to customize the error_handler such that when a HTTP 0 is thrown, the error is ignored and the rest of the Anvil form’s code continues on.

Any suggestions? Especially ones that do not rely throwing the process into the Server side instead of the Client side.

Thank you.

def error_handler(err):
  alert(str(err), title="An error has occurred")

set_default_error_handling(error_handler)

Have you tried a try/except block? If the code is throwing an exception, that’s the best way to ignore it.

That is the best/simplest solution. I was making it way more complicated than I needed to. Thank you.

1 Like

I spoke too soon. Turns out the try/except block doesn’t help my situation.

anvil.http.request(url=myUrl,method=“GET”)

When running this OUTSIDE a try/except block:
Good: The data posts to the external URL successfully
Bad: an error 0 is thrown stopping all other execution on the Anvil form

When running this INSIDE a try/except block:
Bad: The data does NOT post to the url
Good: I can have remaining code of Anvil form execute

I’m still hunting for a way to successfully run the request to the url AND ignore the resulting Error 0 it produces.

Thank you.

Can you boil this down to a simple app to reproduce the issue and post a clone link?

1 Like

I apologize for the delay. In creating the simple app I think I discovered my roadblock. The try/except solution you recommended seems to successfully bypass the execution stoppage for me only if the app does NOT include the set_default_error_handling(error_handler) option having been set.

I had assumed that the above option would fire in exactly the same situations that the “red box” default error alert does. It appears that the custom error handler option is more sensitive to activity within the try/except area. When I removed the custom error handling code, my app was able to continue on.

Thanks again.

Doug

That’s not the way it’s supposed to work. set_default_error_handling only handles uncaught errors.

Here’s a clone that demonstrates this: Anvil | Login

One button calls a server function that handles an exception, another calls a server function that doesn’t handle the exception. The default error function is only called for the second function for me.

There may be something more going on in your example.

1 Like