[Libreoffice-commits] online.git: 2 commits - loleaflet/dist loleaflet/src loolwsd/LOOLWSD.cpp loolwsd/test loolwsd/UserMessages.hpp

Henry Castro hcastro at collabora.com
Wed Oct 12 16:42:35 UTC 2016


 loleaflet/dist/errormessages.js |    1 +
 loleaflet/src/core/Socket.js    |    4 ++++
 loolwsd/LOOLWSD.cpp             |   15 +++++++++------
 loolwsd/UserMessages.hpp        |    4 ++--
 loolwsd/test/httpwstest.cpp     |    6 ++----
 5 files changed, 18 insertions(+), 12 deletions(-)

New commits:
commit 5a2fe805dbd2ea0be5255ebfe219f1f8ff2a93e1
Author: Henry Castro <hcastro at collabora.com>
Date:   Wed Oct 12 11:52:29 2016 -0400

    loleaflet: add localizable error message

diff --git a/loleaflet/dist/errormessages.js b/loleaflet/dist/errormessages.js
index 625f017..47a81fa 100644
--- a/loleaflet/dist/errormessages.js
+++ b/loleaflet/dist/errormessages.js
@@ -2,3 +2,4 @@ exports.wrongwopisrc = _('Wrong WOPISrc, usage: WOPISrc=valid encoded URI, or fi
 exports.emptyhosturl = _('The host URL is empty. The loolwsd server is probably misconfigured, please contact the administrator.');
 exports.diskfull = _('No disk space left on server, please contact the server administrator to continue.');
 exports.limitreached = _('This development build is limited to %0 documents, and %1 connections - to avoid the impression that it is suitable for deployment in large enterprises. To find out more about deploying and scaling %2 checkout: <br/><a href=\"%3\">%3</a>.');
+exports.serviceunavailable = _('Service is unavailable. Please try again later and report to your administrator if the issue persists.');
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 34608e9..1e44434 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -209,6 +209,10 @@ L.Socket = L.Class.extend({
 				textMsg = textMsg.replace(/%2/g, (typeof brandProductName !== 'undefined' ? brandProductName : 'LibreOffice Online'));
 				textMsg = textMsg.replace(/%3/g, (typeof brandProductURL !== 'undefined' ? brandProductURL : 'https://wiki.documentfoundation.org/Development/LibreOffice_Online'));
 			}
+			else if (command.errorKind === 'serviceunavailable') {
+				this._map._fatal = true;
+				textMsg = errorMessages.serviceunavailable;
+			}
 			this._map.fire('error', {msg: textMsg});
 		}
 		else if (textMsg.startsWith('pong ') && this._map._docLayer && this._map._docLayer._debug) {
commit bd5e138aa9831b32d30711974d3c1eb7f191bf2c
Author: Henry Castro <hcastro at collabora.com>
Date:   Wed Oct 12 11:15:32 2016 -0400

    loolwsd: fix error message localization

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 8b6e601..01b7b2a 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -183,7 +183,7 @@ namespace {
 static inline
 void shutdownLimitReached(WebSocket& ws)
 {
-    const std::string error = Poco::format(PAYLOAD_UNAVALABLE_LIMIT_REACHED, MAX_DOCUMENTS, MAX_CONNECTIONS);
+    const std::string error = Poco::format(PAYLOAD_UNAVAILABLE_LIMIT_REACHED, MAX_DOCUMENTS, MAX_CONNECTIONS);
 
     /* loleaflet sends loolclient, load and partrectangles message immediately
        after web socket handshake, so closing web socket fails loading page in
@@ -395,7 +395,7 @@ private:
         {
             // Let the client know we can't serve now.
             Log::error(session->getName() + ": Failed to connect to lokit process. Client cannot serve now.");
-            throw WebSocketErrorMessageException(SERVICE_UNAVALABLE_INTERNAL_ERROR);
+            throw WebSocketErrorMessageException(SERVICE_UNAVAILABLE_INTERNAL_ERROR);
         }
 
         Log::debug("Waiting child session permission, done!");
@@ -727,7 +727,7 @@ private:
             {
                 // Let the client know we can't serve now.
                 Log::error("Failed to get new child. Service Unavailable.");
-                throw WebSocketErrorMessageException(SERVICE_UNAVALABLE_INTERNAL_ERROR);
+                throw WebSocketErrorMessageException(SERVICE_UNAVAILABLE_INTERNAL_ERROR);
             }
 
 #if MAX_DOCUMENTS > 0
@@ -760,7 +760,7 @@ private:
 #endif
             }
 
-            throw WebSocketErrorMessageException(SERVICE_UNAVALABLE_INTERNAL_ERROR);
+            throw WebSocketErrorMessageException(SERVICE_UNAVAILABLE_INTERNAL_ERROR);
         }
 
         // Validate the URI and Storage before moving on.
@@ -878,6 +878,10 @@ private:
             LOOLWSD::dumpEventTrace(docBroker->getJailId(), id, "EndSession: " + uri);
             Log::info("Finishing GET request handler for session [" + id + "].");
         }
+        catch (const WebSocketErrorMessageException&)
+        {
+            throw;
+        }
         catch (const std::exception& exc)
         {
             Log::error("Error in client request handler: " + std::string(exc.what()));
@@ -1048,8 +1052,7 @@ public:
                     Log::error(std::string("ClientRequestHandler::handleRequest: WebSocketErrorMessageException: ") + exc.what());
                     try
                     {
-                        const std::string msg = std::string("error: ") + exc.what();
-                        ws->sendFrame(msg.data(), msg.size());
+                        ws->sendFrame(exc.what(), std::strlen(exc.what()));
                         // abnormal close frame handshake
                         ws->shutdown(WebSocket::WS_ENDPOINT_GOING_AWAY);
                     }
diff --git a/loolwsd/UserMessages.hpp b/loolwsd/UserMessages.hpp
index 7883fc0..742a13c 100644
--- a/loolwsd/UserMessages.hpp
+++ b/loolwsd/UserMessages.hpp
@@ -13,8 +13,8 @@
 #define INCLUDED_USERMESSAGES_HPP
 
 //NOTE: For whatever reason Poco seems to trim the first character.
-constexpr auto SERVICE_UNAVALABLE_INTERNAL_ERROR = " Service is unavailable. Please try again later and report to your administrator if the issue persists.";
-constexpr auto PAYLOAD_UNAVALABLE_LIMIT_REACHED = "error: cmd=socket kind=limitreached params=%d,%d";
+constexpr auto SERVICE_UNAVAILABLE_INTERNAL_ERROR = "error: cmd=socket kind=serviceunavailable";
+constexpr auto PAYLOAD_UNAVAILABLE_LIMIT_REACHED = "error: cmd=socket kind=limitreached params=%d,%d";
 
 #endif
 
diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp
index 6876218..83115d2 100644
--- a/loolwsd/test/httpwstest.cpp
+++ b/loolwsd/test/httpwstest.cpp
@@ -270,22 +270,20 @@ void HTTPWSTest::testHandShake()
             else
             {
                 // check error message
-                CPPUNIT_ASSERT(std::strstr(buffer, SERVICE_UNAVALABLE_INTERNAL_ERROR) != nullptr);
+                CPPUNIT_ASSERT(std::strstr(SERVICE_UNAVAILABLE_INTERNAL_ERROR, buffer) != nullptr);
 
                 // close frame message
                 bytes = socket.receiveFrame(buffer, sizeof(buffer), flags);
-                CPPUNIT_ASSERT(std::strstr(buffer, SERVICE_UNAVALABLE_INTERNAL_ERROR) != nullptr);
                 CPPUNIT_ASSERT((flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) == Poco::Net::WebSocket::FRAME_OP_CLOSE);
             }
         }
         else
         {
             // check error message
-            CPPUNIT_ASSERT(std::strstr(buffer, SERVICE_UNAVALABLE_INTERNAL_ERROR) != nullptr);
+            CPPUNIT_ASSERT(std::strstr(SERVICE_UNAVAILABLE_INTERNAL_ERROR, buffer) != nullptr);
 
             // close frame message
             bytes = socket.receiveFrame(buffer, sizeof(buffer), flags);
-            CPPUNIT_ASSERT(std::strstr(buffer, SERVICE_UNAVALABLE_INTERNAL_ERROR) != nullptr);
             CPPUNIT_ASSERT((flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) == Poco::Net::WebSocket::FRAME_OP_CLOSE);
         }
     }


More information about the Libreoffice-commits mailing list