Show detailed error message for HubExceptions (#2461)

This commit is contained in:
Mikael Mengistu 2018-06-11 13:55:47 -07:00 committed by GitHub
parent 0306038658
commit c7ebae47ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 3 deletions

View File

@ -9,12 +9,13 @@ namespace Microsoft.AspNetCore.SignalR.Internal
{
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;
}
}
}

View File

@ -121,6 +121,11 @@ namespace Microsoft.AspNetCore.SignalR.Tests
throw new InvalidOperationException("BOOM!");
}
public void ThrowHubException()
{
throw new HubException("This is a hub exception");
}
public Task MethodThatYieldsFailedTask()
{
return Task.FromException(new InvalidOperationException("BOOM!"));

View File

@ -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]
public async Task HubMethodDoesNotSendResultWhenInvocationIsNonBlocking()
{