第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何識別 JavaScript 客戶端上的 SignalR 核心集線器錯誤?

如何識別 JavaScript 客戶端上的 SignalR 核心集線器錯誤?

喵喵時光機 2023-09-07 16:51:46
我們正在嘗試在 JavaScript 客戶端的 SignalR Core 調(diào)用方法上設(shè)置錯誤處理,該客戶端需要識別錯誤的類型并采取相應(yīng)的操作(例如,如果是授權(quán)錯誤,則應(yīng)提示用戶登錄等)。我們確定從集線器返回的錯誤包含一條消息和一個堆棧屬性,并構(gòu)建了以下內(nèi)容,根據(jù)消息屬性中包含的文本設(shè)置錯誤代碼:錯誤文本是否總是以英文返回(因此可以用于識別錯誤)?或者有更好的方法來實現(xiàn)這一目標(biāo)嗎?我們正在使用 .Net Core 3.1 和 @microsoft/signalr 3.1.10。
查看完整描述

1 回答

?
aluckdog

TA貢獻1847條經(jīng)驗 獲得超7個贊

根據(jù)GitHub上的aspnetcore/SignalR服務(wù)器端代碼,看來調(diào)用錯誤確實是通過字符串值傳遞的。


負責(zé)發(fā)送錯誤的方法定義如下:


private async Task SendInvocationError(string invocationId, HubConnectionContext connection, string errorMessage)

{

    if (string.IsNullOrEmpty(invocationId))

    {

        return;

    }


    await connection.WriteAsync(CompletionMessage.WithError(invocationId, errorMessage));

}

以及一些關(guān)于如何調(diào)用它的示例:


if (!await IsHubMethodAuthorized(scope.ServiceProvider, connection, descriptor, hubMethodInvocationMessage.Arguments, hub))

{

    Log.HubMethodNotAuthorized(_logger, hubMethodInvocationMessage.Target);

    await SendInvocationError(hubMethodInvocationMessage.InvocationId, connection,

        $"Failed to invoke '{hubMethodInvocationMessage.Target}' because user is unauthorized");

    return;

}

var errorMessage = ErrorMessageHelper.BuildErrorMessage($"Failed to invoke '{bindingFailureMessage.Target}' due to an error on the server.",

    bindingFailureMessage.BindingFailure.SourceException, _enableDetailedErrors);

return SendInvocationError(bindingFailureMessage.InvocationId, connection, errorMessage);

有關(guān)錯誤的唯一信息是 的字符串參數(shù)errorMessage。


另一方面,客戶端 javascript 庫源代碼:


HubConnection.prototype.connectionClosed = function (error) {

    this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Debug, "HubConnection.connectionClosed(" + error + ") called while in state " + this.connectionState + ".");

    // Triggering this.handshakeRejecter is insufficient because it could already be resolved without the continuation having run yet.

    this.stopDuringStartError = this.stopDuringStartError || error || new Error("The underlying connection was closed before the hub handshake could complete.");

    // If the handshake is in progress, start will be waiting for the handshake promise, so we complete it.

    // If it has already completed, this should just noop.

    if (this.handshakeResolver) {

        this.handshakeResolver();

    }

    this.cancelCallbacksWithError(error || new Error("Invocation canceled due to the underlying connection being closed."));

    

    ...

};

這表明這"Invocation canceled due to the underlying connection being closed."是服務(wù)器未提供任何信息時的默認錯誤消息。


因此,我相信如果SignalR團隊沒有改變錯誤消息發(fā)送機制,你的string.includes做法是合理的。


查看完整回答
反對 回復(fù) 2023-09-07
  • 1 回答
  • 0 關(guān)注
  • 111 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號