|
|
@@ -297,19 +297,9 @@ namespace Microsoft.JSInterop
|
|
|
public void CanSanitizeDotNetInteropExceptions()
|
|
|
{
|
|
|
// Arrange
|
|
|
- var expectedMessage = "An error ocurred while invoking '[Assembly]::Method'. Swapping to 'Development' environment will " +
|
|
|
- "display more detailed information about the error that occurred.";
|
|
|
-
|
|
|
- string GetMessage(DotNetInvocationInfo info) => $"An error ocurred while invoking '[{info.AssemblyName}]::{info.MethodIdentifier}'. Swapping to 'Development' environment will " +
|
|
|
- "display more detailed information about the error that occurred.";
|
|
|
-
|
|
|
- var runtime = new TestJSRuntime()
|
|
|
- {
|
|
|
- OnDotNetException = (invocationInfo) => new JSError { Message = GetMessage(invocationInfo) }
|
|
|
- };
|
|
|
-
|
|
|
+ var runtime = new TestJSRuntime();
|
|
|
var exception = new Exception("Some really sensitive data in here");
|
|
|
- var invocation = new DotNetInvocationInfo("Assembly", "Method", 0, "0");
|
|
|
+ var invocation = new DotNetInvocationInfo("TestAssembly", "TestMethod", 0, "0");
|
|
|
var result = new DotNetInvocationResult(exception, default);
|
|
|
|
|
|
// Act
|
|
|
@@ -319,13 +309,22 @@ namespace Microsoft.JSInterop
|
|
|
var call = runtime.EndInvokeDotNetCalls.Single();
|
|
|
Assert.Equal("0", call.CallId);
|
|
|
Assert.False(call.Success);
|
|
|
- var jsError = Assert.IsType<JSError>(call.ResultOrError);
|
|
|
- Assert.Equal(expectedMessage, jsError.Message);
|
|
|
+
|
|
|
+ var error = Assert.IsType<JSError>(call.ResultError);
|
|
|
+ Assert.Same(exception, error.InnerException);
|
|
|
+ Assert.Equal(invocation, error.InvocationInfo);
|
|
|
}
|
|
|
|
|
|
private class JSError
|
|
|
{
|
|
|
- public string? Message { get; set; }
|
|
|
+ public DotNetInvocationInfo InvocationInfo { get; set; }
|
|
|
+ public Exception? InnerException { get; set; }
|
|
|
+
|
|
|
+ public JSError(DotNetInvocationInfo invocationInfo, Exception? innerException)
|
|
|
+ {
|
|
|
+ InvocationInfo = invocationInfo;
|
|
|
+ InnerException = innerException;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private class TestPoco
|
|
|
@@ -359,24 +358,18 @@ namespace Microsoft.JSInterop
|
|
|
{
|
|
|
public string? CallId { get; set; }
|
|
|
public bool Success { get; set; }
|
|
|
- public object? ResultOrError { get; set; }
|
|
|
+ public string? ResultJson { get; set; }
|
|
|
+ public JSError? ResultError { get; set; }
|
|
|
}
|
|
|
|
|
|
- public Func<DotNetInvocationInfo, object>? OnDotNetException { get; set; }
|
|
|
-
|
|
|
protected internal override void EndInvokeDotNet(DotNetInvocationInfo invocationInfo, in DotNetInvocationResult invocationResult)
|
|
|
{
|
|
|
- var resultOrError = invocationResult.Success ? invocationResult.Result : invocationResult.Exception;
|
|
|
- if (OnDotNetException != null && !invocationResult.Success)
|
|
|
- {
|
|
|
- resultOrError = OnDotNetException(invocationInfo);
|
|
|
- }
|
|
|
-
|
|
|
EndInvokeDotNetCalls.Add(new EndInvokeDotNetArgs
|
|
|
{
|
|
|
CallId = invocationInfo.CallId,
|
|
|
Success = invocationResult.Success,
|
|
|
- ResultOrError = resultOrError,
|
|
|
+ ResultJson = invocationResult.ResultJson,
|
|
|
+ ResultError = invocationResult.Success ? null : new JSError(invocationInfo, invocationResult.Exception),
|
|
|
});
|
|
|
}
|
|
|
|