启动客户端连接:

ngOnInit() {
    this._gameKey = parseInt(this._route.snapshot.paramMap.get('game-key'));

    this._hubConnection = new HubConnectionBuilder()
                          .withUrl('http://localhost:5000/match').build();

    this._hubConnection.on('Connected', (data) => {this.connected(data)});

    ...

    this._hubConnection
      .start()
      .then(() => {})
      .catch(err => console.log(err));
}

这是我正在调用的后端方法:

public async Task SendResources(string gameKey) {
      throw new HubException("oops");
      ...
}

在我的打字稿客户端,我有:

public connected(data): void {    
  this._hubConnection.invoke('SendResources', this._gameKey).catch(this.errorHandler);
}

public errorHandler(err): void {
  console.log(err);
}

执行流程输入'errorHandler',其中'err'的类型为Error . 问题是我无法访问异常消息 . 我从'err'变量获得的所有信息都是这样的:

enter image description here

任何想法如何使用signalR正确处理错误消息?

版本:

.net核心:2.1
角度:5
@ aspnet / signalr:1.0.0