Page 1 of 1

[SOLVED] WebClient async methods do not throw Exceptions properly in JS output

Posted: Mon Jul 15, 2019 11:21 am
by TaterJuice
Using the WebClientWithAuth class from CSHTML 1.2.3, exception handling for WebClient async tasks only works in the simulator, it does not work in output js and instead produces a javascript console error.

Code: Select all

client.DownloadString(); //handles exceptions
client.DownloadStringAsync(); // does NOT handle exceptions
client.DownloadStringTaskAsync(); // does NOT handle exceptions


For example, if I take my API down and attempt to authenticate with it, in Simulator I get an exception,
Unable to connect to the remote server at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request) at System.Net.WebClient.DownloadString(Uri address)

I can catch this error in a try/catch block, and then notify the user of the error and prevent further execution of my task.

In the JS output, I get no exception, just the following error in the js console:
Failed to load resource: net::ERR_CONNECTION_REFUSED

This does NOT get caught in a try/catch block, I cannot notify the user of the error, and it does not prevent further execution of my task.

My current workaround is to only use `client.DownloadString()`, instead of any of the async methods.

Re: WebClient async methods do not throw Exceptions properly in JS output

Posted: Tue Jul 16, 2019 3:08 am
by JS-Support @Userware
Hi,

Thanks for reporting this issue.

1. Did it occur also with the previous version 1.2.2 (or older), or is it a regression?

2. Did you have a chance to test it with version 2.x yet?

Thanks.
Regards

Re: WebClient async methods do not throw Exceptions properly in JS output

Posted: Tue Jul 16, 2019 7:05 am
by TaterJuice
JS-Support @Userware wrote:Hi,

Thanks for reporting this issue.

1. Did it occur also with the previous version 1.2.2 (or older), or is it a regression?

2. Did you have a chance to test it with version 2.x yet?

Thanks.
Regards


1. I don't know. This is the first time I've used the CSHTML5 webclient in production. Prior to this I was using a jQuery.ajax wrapper class.

2. I have not tested in 2.0. I was not able to get my project bug-free in 2.0 (due to many issues with data-binding and debug breakpoints getting skipped).

Re: WebClient async methods do not throw Exceptions properly in JS output

Posted: Wed Jul 17, 2019 2:51 am
by JS-Support @Userware
Thanks. We are going to look into it and keep you updated.

Re: WebClient async methods do not throw Exceptions properly in JS output

Posted: Wed Jul 17, 2019 10:45 am
by TaterJuice
It seems none of the webClient.UploadString methods handle exceptions properly.

For example, if the connection is interrupted, I see a js console error "Failed to load resource: net::ERR_CONNECTION_REFUSED" in the js output, but it is not caught in a try/catch block, and my app attempts to continue execution without being aware of the error.

if the server returns a 500 internal server error, I see a js console error "Failed to load resource: the server responded with a status of 500 ()" but again, it is not caught in a try/catch block, and my app attempts to continue execution without being aware of the error.

What are the chances these will be fix before August 1st? I have a release deadline for August 1st and I'm afraid this is going to delay me.

Re: WebClient async methods do not throw Exceptions properly in JS output

Posted: Fri Jul 19, 2019 3:36 am
by JS-Support @Userware
Thanks for your message.

We have recently improved error handling in WCF calls, in the following changeset:
https://github.com/cshtml5/CSHTML5/commit/7fa5ef61f7ee96e7ba3c2574cd79a77343a82b84

Similar fixes need to be done for WebClient calls. We'll look into it asap (unless a community member has time to look into it before us).

Thanks a lot.

Re: WebClient async methods do not throw Exceptions properly in JS output

Posted: Mon Jul 22, 2019 2:03 pm
by TaterJuice
I would be happy to help, so I can make my deadline.

Whats the best way to contribute? Should I completely rewrite the webclient based on your 2.0 source, or is there a simpler way to just override the uploadstring methods? I'm trying to browse your source, and I see a lot of "JS Interop Replace With" attributes, but I can't get a dll to compile using those attributes, so I think I'll need to refactor your source completely, using JS Interop calls. Am I missing something?

Re: WebClient async methods do not throw Exceptions properly in JS output

Posted: Tue Jul 23, 2019 4:27 am
by JS-Support @Userware
The best way to contribute would be first to transition to v2.0 and then directly improve the CSHTML5 source code by cloning it from GitHub and following the instructions at:
https://github.com/cshtml5/CSHTML5

You said that you were not able to get your project bug-free in 2.0 due to many issues with data-binding and debug breakpoints getting skipped.

Could you please tell us more about the data-binding issues and how to reproduce them?

As far as the debug breakpoints are concerned, could you please attempt to check the options shown in the screenshot below?
screenshot_vs_debugging_options_to_check.png
screenshot_vs_debugging_options_to_check.png (69.79 KiB) Viewed 2348 times


Thank you very much!

Re: WebClient async methods do not throw Exceptions properly in JS output

Posted: Wed Aug 07, 2019 8:28 am
by JS-Support @Userware
Hi,

We have fixed the try/catch handling when using the async methods of the WebClient.

Please expect the fix to be available in the next NuGet package update.

Thanks
Regards

Re: WebClient async methods do not throw Exceptions properly in JS output

Posted: Wed Aug 07, 2019 10:05 am
by TaterJuice
JS-Support @Userware wrote:Hi,

We have fixed the try/catch handling when using the async methods of the WebClient.

Please expect the fix to be available in the next NuGet package update.

Thanks
Regards

Thanks for the message.
Will the current 1.2 release be updated?

Re: WebClient async methods do not throw Exceptions properly in JS output

Posted: Tue Aug 20, 2019 9:22 am
by JS-Support @Userware
Hi,

This issue has been fixed in CSHTML5 version 2.0.0-alpha43-061, which is now available on NuGet.

The version 1.2.4 will be released asap, but we still have a few regressions to fix, because we are attempting to maintain both v1.x and 2.x with the same codebase.

Thanks.
Regards

Re: WebClient async methods do not throw Exceptions properly in JS output

Posted: Tue Aug 20, 2019 10:00 pm
by TaterJuice
Awesome. Looking forward to it!