Context: There are differences between ASP.NET SignalR and ASP.NET Core SignalR you can read here.
As described in this stackoverflow post in ASP.NET SignalR you can catch unhandled exceptions on server side via the HubPipelineModule
which not exists in ASP.NET Core SignalR.
How can we catch unhandled exceptions and pass them to the client side in ASP.NET Core SignalR?
JavaScript code (client):
var hub = null;
var initWebSocket = function () {
hub = new signalR.HubConnectionBuilder().withUrl("/MyHub").build();
hub.on("ReceiveMessage", function (pMessage) {
[...]
});
hub.start().catch(function (err) {
return console.error(err.toString());
});
};
var executeWebsocketTestException = function () {
// send to server
hub.invoke("TestException").catch(function (exception) {
if(exception.type)
{
...
}
});
};
ASP.NET Core 2 Hub (server):
public class MyHub : Hub
{
public async Task TestException()
{
throw new SignalRTest.Exceptions.TestException("This is a Websocket Test Exception.");
}
}