Show detailed error message for HubExceptions (#2461)
This commit is contained in:
parent
0306038658
commit
c7ebae47ea
|
|
@ -9,12 +9,13 @@ namespace Microsoft.AspNetCore.SignalR.Internal
|
||||||
{
|
{
|
||||||
internal static string BuildErrorMessage(string message, Exception exception, bool includeExceptionDetails)
|
internal static string BuildErrorMessage(string message, Exception exception, bool includeExceptionDetails)
|
||||||
{
|
{
|
||||||
if (!includeExceptionDetails)
|
if (exception is HubException || includeExceptionDetails)
|
||||||
{
|
{
|
||||||
return message;
|
return $"{message} {exception.GetType().Name}: {exception.Message}";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return message + $" {exception.GetType().Name}: {exception.Message}";
|
return message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,11 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
throw new InvalidOperationException("BOOM!");
|
throw new InvalidOperationException("BOOM!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ThrowHubException()
|
||||||
|
{
|
||||||
|
throw new HubException("This is a hub exception");
|
||||||
|
}
|
||||||
|
|
||||||
public Task MethodThatYieldsFailedTask()
|
public Task MethodThatYieldsFailedTask()
|
||||||
{
|
{
|
||||||
return Task.FromException(new InvalidOperationException("BOOM!"));
|
return Task.FromException(new InvalidOperationException("BOOM!"));
|
||||||
|
|
|
||||||
|
|
@ -540,6 +540,30 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task DetailedExceptionEvenWhenNotExplicitlySet()
|
||||||
|
{
|
||||||
|
var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider();
|
||||||
|
|
||||||
|
var methodName = nameof(MethodHub.ThrowHubException);
|
||||||
|
|
||||||
|
var connectionHandler = serviceProvider.GetService<HubConnectionHandler<MethodHub>>();
|
||||||
|
|
||||||
|
using (var client = new TestClient())
|
||||||
|
{
|
||||||
|
var connectionHandlerTask = await client.ConnectAsync(connectionHandler);
|
||||||
|
|
||||||
|
var message = await client.InvokeAsync(methodName).OrTimeout();
|
||||||
|
|
||||||
|
Assert.Equal($"An unexpected error occurred invoking '{methodName}' on the server. HubException: This is a hub exception", message.Error);
|
||||||
|
|
||||||
|
// kill the connection
|
||||||
|
client.Dispose();
|
||||||
|
|
||||||
|
await connectionHandlerTask.OrTimeout();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task HubMethodDoesNotSendResultWhenInvocationIsNonBlocking()
|
public async Task HubMethodDoesNotSendResultWhenInvocationIsNonBlocking()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue