Makla
Makla

Reputation: 10459

Get detailed error for exception in SignalR Core Hub method execution

When I call Hub method I get frame response:

{"invocationId":"1","type":3,"error":"An error occurred while updating the entries. See the inner exception for details."}

How can I get detailed error report (row and file where error occurred) without manually debugging and using step over and check where the code raise exception.

On net I found plenty codes where EnableDetailedErrors is used

services.AddSignalR(options => 
        {
            options.Hubs.EnableDetailedErrors = true;
        });

but options (at least in version 1.0.0-alpha2-final) does not have property Hubs.

Upvotes: 5

Views: 5654

Answers (2)

Simon_Weaver
Simon_Weaver

Reputation: 146110

This is what you need to do in core (not sure the exact version this was added):

        // signalR
        services.AddSignalR(options =>
        {
            if (Environment.IsDevelopment()) {
                options.EnableDetailedErrors = true;
            }
        });

It goes without saying that the reason this is disabled by default in production is for security reasons. So be careful not to expose things you may not wish 'hackers' to see in any of the exceptions you may throw.

Implementing the above setting will reveal a more detailed message in the browser console, whcih you can also see in the websocket debugging tab:

enter image description here


Quick tip:

I've set up SignalR twice now on ASPNetCore and I think I've made the same mistake both times:

// from typescript client arguments are passed like this
this.hubConnection.invoke('SendMessage', 'simon', 'hello');

// not like this
this.hubConnection.invoke('SendMessage', ['simon', 'hello']);

Also invoke will wait for a response, while send does not. So you may not see errors using send.

Upvotes: 13

Pawel
Pawel

Reputation: 31610

Currently the option to enable detailed errors is not implemented. There is an issue tracking this. My recommendation would be to turn on logging on the server side - the original exception will be logged there.

Upvotes: 6

Related Questions