-
Notifications
You must be signed in to change notification settings - Fork 564
[AndroidClientHandler] Wrap Java exceptions in .NET ones #4601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Or maybe the BCL tests for Mono or .NET Core include some |
| if (redirectState.NewUrl == null) | ||
| throw new InvalidOperationException ("Request redirected but no new URI specified"); | ||
| request.Method = redirectState.Method; | ||
| } catch (Java.Net.SocketTimeoutException ex) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @brendanzagaeski pointed out, these catch blocks should use when (JNIEnv.ShouldWrapJavaException (ex)), as was done in 60363ef.
Context: 60363ef This commit a follow-up to 60363ef in that it causes less Java exceptions to "leak" to applications which use code shared between platforms that might not be able to check for Java exception types directly (because they don't link against `Mono.Android.dll`). However, instead of making the behavior optional, as implemented in 60363ef, this commit unconditionally wraps `Java.IO.Exception` and some of its derivatives in the standard .NET `WebException`. This makes the handler to behave in a manner that's closer to how other `HttpClient` custom handlers behave. The `$(AndroidBoundExceptionType)` MSBuild property must be set to `System` in order to use the wrapped exceptions.
2353cfd to
eda6631
Compare
|
@brendanzagaeski I'm in two minds regarding Regarding tests... Yeah, it would be nice, but testing network behaviors is hard and in our case we can't mock the requests - we must issue actual requests to actual servers, so that the Java backend actually kicks in. Yes, we could make our code mockable by introducing a fake Java backend that would throw certain exceptions at certain points, but I honestly don't see much value in it. Regarding the test servers - we've been wanting to do it for quite a while now (to use https://httpbin.org/ on the test servers so we can perform all kinds of tests in controlled manner) but so far it hasn't happened. When we have a server we can rely on and fully control (in the |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
The underlying intent behind 60363ef was that ".NET methods" should throw only documented exception types.
|
HttpClient.SendAsync() also throws HttpRequestException: https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.sendasync?view=netcore-3.1#System_Net_Http_HttpClient_SendAsync_System_Net_Http_HttpRequestMessage_System_Threading_CancellationToken_
This reverts commit 637a210. Won't build. nm.
|
…except:
Nor are the Thus, if everything is meaningless, go with the type that provides the most useful info: |
Context: 60363ef Follow-up to 60363ef, and update `AndroidClientHandler.SendAsync()` to optionally wrap Java exception types with `WebException`, so that Java exception types don't "leak" into code which is written against e.g. .NET Standard 2.0. To enable Java exception wrapping, the `$(AndroidBoundExceptionType)` MSBuild property must be set to `System`.
Context: 60363ef
This commit is, in a way, a follow-up to 60363ef in that it causes less
Java exceptions to "leak" to applications which use code shared between
platforms that might not be able to check for Java exception types
directly (because they don't link against
Mono.Android.dll). However,instead of making the behavior optional, as implemented in 60363ef,
this commit unconditionally wraps
Java.IO.Exceptionand some of itsderivatives in the standard .NET
WebException. This makes the handlerto behave in a manner that's closer to how other
HttpClientcustomhandlers behave.