loleaflet/reference.html     |   16 ++++++++++++++++
 loleaflet/src/core/Socket.js |    7 +++++++
 wsd/LOOLWSD.cpp              |   19 +++++++++++++++++++
 wsd/Storage.cpp              |    7 +++++--
 4 files changed, 47 insertions(+), 2 deletions(-)

New commits:
commit ce91fa4201a53400e677857b6a1c82ee4e8606ec
Author:     Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
AuthorDate: Tue Jul 7 21:18:13 2020 +0200
Commit:     Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
CommitDate: Wed Jul 15 09:48:43 2020 +0200

    Report back load result to integrator
    
    Integrator currently gets no message when loading the document
    from WOPI host fails.
    
    Similiar to Action_Save_Resp, introduce Action_Load_Resp with
    the result of the load action.
    
    Change-Id: I3b0f9ee691a1c5d58e9f833d511435a0b25a465f
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/98299
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@cib.de>

diff --git a/loleaflet/reference.html b/loleaflet/reference.html
index 99cae5ec6..4c07de27d 100644
--- a/loleaflet/reference.html
+++ b/loleaflet/reference.html
@@ -3035,6 +3035,22 @@ Editor to WOPI host
                <th>Values</th>
                <th>Description</th>
        </tr>
+       <tr>
+               <td><code><b>Action_Load_Resp</b></code></td>
+               <td><code>
+                       <nobr>success: &lt;boolean&gt;</nobr>
+                       <nobr>result: &lt;string&gt;</nobr>
+                       <nobr>errorMsg: &lt;string&gt;</nobr>
+               </code></td>
+               <td>Acknowledgement when load finishes.<br/>
+               <code>success</code> tells if LOOL was able to load the document
+               successfully.<br/>
+               <code>result</code> contains the reason the document was not 
loaded.<br/>
+               <code>errorMsg</code> contains a detailed error message in case 
loading failed.
+               Probably it will contain the error message returned from the 
WOPI/Webdav host.
+               </td>
+       </tr>
+
        <tr>
                <td><code><b>Action_Save_Resp</b></code></td>
                <td><code>
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 9b9b3c236..790c7885d 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -370,6 +370,13 @@ L.Socket = L.Class.extend({
                                        errorMsg: commandresult['errorMsg']
                                };
                                this._map.fire('postMessage', {msgId: 
'Action_Save_Resp', args: postMessageObj});
+                       } else if (commandresult['command'] === 'load') {
+                               postMessageObj = {
+                                       success: commandresult['success'],
+                                       result: commandresult['result'],
+                                       errorMsg: commandresult['errorMsg']
+                               };
+                               this._map.fire('postMessage', {msgId: 
'Action_Load_Resp', args: postMessageObj});
                        }
                        return;
                }
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index cef10cc11..1df218e83 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -690,6 +690,20 @@ inline std::string getServiceURI(const std::string &sub, 
bool asAdmin = false)
 
 #endif
 
+void sendLoadResult(std::shared_ptr<ClientSession> clientSession, bool success,
+                    const std::string &errorMsg)
+{
+    const std::string result = success ? "" : "Error while loading document";
+    const std::string resultstr = success ? "true" : "false";
+    // Some sane limit, otherwise we get problems transfering this
+    // to the client with large strings (can be a whole webpage)
+    // Replace reserved characters
+    std::string errorMsgFormatted = 
LOOLProtocol::getAbbreviatedMessage(errorMsg);
+    errorMsgFormatted = Poco::translate(errorMsg, "\"", "'");
+    clientSession->sendMessage("commandresult: { \"command\": \"load\", 
\"success\": " + resultstr +
+                    ", \"result\": \"" + result + "\", \"errorMsg\": \"" + 
errorMsgFormatted  + "\"}");
+}
+
 } // anonymous namespace
 
 #endif // MOBILEAPP
@@ -3235,15 +3249,19 @@ private:
                                 // Users of development versions get just an 
info
                                 // when reaching max documents or connections
                                 LOOLWSD::checkSessionLimitsAndWarnClients();
+
+                                sendLoadResult(clientSession, true, "");
                             }
                             catch (const UnauthorizedRequestException& exc)
                             {
                                 LOG_ERR("Unauthorized Request while loading 
session for " << docBroker->getDocKey() << ": " << exc.what());
+                                sendLoadResult(clientSession, false, 
"Unauthorized Request");
                                 const std::string msg = "error: cmd=internal 
kind=unauthorized";
                                 clientSession->sendMessage(msg);
                             }
                             catch (const StorageConnectionException& exc)
                             {
+                                sendLoadResult(clientSession, false, 
exc.what());
                                 // Alert user about failed load
                                 const std::string msg = "error: cmd=storage 
kind=loadfailed";
                                 clientSession->sendMessage(msg);
@@ -3255,6 +3273,7 @@ private:
                                 // Alert user about failed load
                                 const std::string msg = "error: cmd=storage 
kind=loadfailed";
                                 clientSession->sendMessage(msg);
+                                sendLoadResult(clientSession, false, 
exc.what());
                             }
                         });
                     });
diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp
index e15f1abcb..e67c568ac 100644
--- a/wsd/Storage.cpp
+++ b/wsd/Storage.cpp
@@ -898,8 +898,11 @@ std::string WopiStorage::loadStorageFileToLocal(const 
Authorization& auth,
 
         if (response.getStatus() != Poco::Net::HTTPResponse::HTTP_OK)
         {
-            LOG_ERR("WOPI::GetFile failed with " << response.getStatus() << ' 
' << response.getReason());
-            throw StorageConnectionException("WOPI::GetFile failed");
+            std::ostringstream oss;
+            Poco::StreamCopier::copyStream(rs, oss);
+            std::string responseString = oss.str();
+            LOG_ERR("WOPI::GetFile failed with " << response.getStatus() << ' 
' << responseString);
+            throw StorageConnectionException("WOPI::GetFile failed: " + 
responseString);
         }
         else // Successful
         {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to