2

启动连接客户端:

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' 变量中获得的所有信息都是这样的:

在此处输入图像描述

知道如何使用 signalR 正确处理错误消息吗?

版本:

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

4

0 回答 0