From d4918c79981058dce6d9071d2d64ce8cdb8f8c29 Mon Sep 17 00:00:00 2001 From: Rash419 Date: Fri, 15 Dec 2023 13:55:42 +0530 Subject: [PATCH] improve error message on invalid WOPI host - before this patch when socket connection failed, we used to show the same error for socket connection failure and send the 'Action_Load_Resp' with same errorMsg - now we show/send different message for unauthorized and loading failure Signed-off-by: Rash419 Change-Id: I71b1b7f8e2eca93790d068583370787825911a41 --- browser/src/core/Socket.js | 29 ++++++++++++++++++++++++----- browser/src/errormessages.js | 3 ++- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/browser/src/core/Socket.js b/browser/src/core/Socket.js index 4776f3356..4b0db47c4 100644 --- a/browser/src/core/Socket.js +++ b/browser/src/core/Socket.js @@ -1542,17 +1542,36 @@ app.definitions.Socket = L.Class.extend({ // Let onclose (_onSocketClose) report errors. }, - _onSocketClose: function () { + _onSocketClose: function (event) { window.app.console.debug('_onSocketClose:'); if (!this._map._docLoadedOnce && this.ReconnectCount === 0) { + var errorMsg, errorType = ''; + var reason = event.reason; + if (reason && reason.startsWith('error:')) { + var command = this.parseServerCmd(reason); + if (command.errorCmd === 'internal' && command.errorKind === 'unauthorized') { + errorType = 'websocketunauthorized'; + errorMsg = errorMessages.unauthorized; + } else if (command.errorCmd === 'storage' && command.errorKind === 'loadfailed') { + errorType = 'websocketloadfailed'; + errorMsg = errorMessages.storage.loadfailed; + } else { + errorType = 'websocketgenericfailure'; + errorMsg = errorMessages.websocketgenericfailure; + } + } else { + errorType = 'websocketproxyfailure'; + errorMsg = errorMessages.websocketproxyfailure; + } + this._map.fire('error', { msg: errorMsg, cmd: 'socket', kind: 'closed', id: 4 }); var postMessageObj = { - errorType: 'websocketconnectionfailed', + errorType: errorType, success: false, - errorMsg: errorMessages.websocketconnectionfailed, + errorMsg: errorMsg, result: '', }; - this._map.fire('postMessage', {msgId: 'Action_Load_Resp', args: postMessageObj}); - this._map.fire('error', {msg: errorMessages.websocketconnectionfailed, cmd: 'socket', kind: 'closed', id: 4}); + this._map.fire('postMessage', { msgId: 'Action_Load_Resp', args: postMessageObj }); + return; } if (this.ReconnectCount > 0) return; diff --git a/browser/src/errormessages.js b/browser/src/errormessages.js index 0e04692b9..cd345d83c 100644 --- a/browser/src/errormessages.js +++ b/browser/src/errormessages.js @@ -36,7 +36,8 @@ errorMessages.docloadtimeout = _('Failed to load the document. This document is errorMessages.docunloadingretry = _('Cleaning up the document from the last session.'); errorMessages.docunloadinggiveup = _('We are in the process of cleaning up this document from the last session, please try again later.'); errorMessages.clusterconfiguration = _('Your %productName cluster appear to be mis-configured or scaling rapidly - please contact your system administrator. Continuing with editing may result in multiple users not seeing each other, conflicts in the document storage and/or copy/paste problems. Expected serverId %0 for routeToken %1 but connected to serverId %2'); -errorMessages.websocketconnectionfailed = _('Failed to establish socket connection or socket connection closed unexpectedly. The reverse proxy might be misconfigured, please contact the administrator. For more info on proxy configuration please checkout https://sdk.collaboraonline.com/docs/installation/Proxy_settings.html'); +errorMessages.websocketproxyfailure = _('Failed to establish socket connection or socket connection closed unexpectedly. The reverse proxy might be misconfigured, please contact the administrator. For more info on proxy configuration please checkout https://sdk.collaboraonline.com/docs/installation/Proxy_settings.html'); +errorMessages.websocketgenericfailure = _('Failed to establish socket connection or socket connection closed unexpectedly.'); if (window.ThisIsAMobileApp) { errorMessages.storage = { loadfailed: _('Failed to load document.'),