Reputation: 775
In the hub i want to authenticate the clients based on Connection Header.
If the client is not allowed to connect, i want to throw an Exception with the detailed error.
But, if i throw an exception on the hub, the client only receives "(500) Internal Server Error"
public override Task OnConnected()
{
string clientKey = Context.Headers["clientKey"];
string version = Context.Headers["version"];
if (!this.isValid(clientKey, version))
throw new InvalidOperationException("SIGNALR: Invalid client");
return base.OnConnected();
}
What i have to do to send the exception properly?
Thanks!
Upvotes: 4
Views: 4916
Reputation: 11
To enable sending error details to clients you should enable this in your Hub configuration. add this line of code in your startup class.
var hubConfiguration = new HubConfiguration {EnableDetailedErrors = true};
app.MapSignalR(hubConfiguration);
Upvotes: 1
Reputation: 133
When error is going to happen you can return that error or return your custom message to the client and based of that message you can redirect the client to Error page or display dialog that indicates that Error has happened.
Don't throw the error on the server side. Return the error on the client side and notify the user
Upvotes: 5