Skip to content

SignalR typescript client: there is no way to catch authorization errors #62952

@antonGritsenko

Description

@antonGritsenko

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I have very simple case: the hub is protected by the authorization policy, so some users can get 302 error when connecting to the hub. I need to catch this and show some some info of the client.

Expected Behavior

I can catch 302 errors.

Steps To Reproduce

connection: signalR.HubConnection;

    this.connection = new signalR.HubConnectionBuilder()
    .withAutomaticReconnect()
    .withUrl(environment.apis.default.url + `/signalr-hubs/call-tracker`, {
      accessTokenFactory: () => this.oAuthService.getAccessToken(),
    })
    .build();

this.connection
      .start()
      .then(() => {
        this.callTrackerConnected = true;
        this.callTrackerStatus = "OK";
        console.log('Connection started');
      })
      .catch(err => {
        this.callTrackerConnected = false;
        this.callTrackerStatus = "ERROR";
        this.callTrackerError = err;
        console.error("Enable to connect to SignalR", err)
        this.connection.stop();
      });

I'm always getting 'Conection started' message in the console and this.connection.state is always Connected

Exceptions (if any)

No response

.NET Version

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Status: Resolvedarea-signalrIncludes: SignalR clients and servers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions