[Libreoffice-commits] online.git: Branch 'distro/collabora/milestone-7' - loleaflet/reference.html loleaflet/src

Jan Holesovsky kendy at collabora.com
Thu Jan 14 12:30:19 PST 2016


 loleaflet/reference.html              |   32 ++++++++++++++++++++++++++++++++
 loleaflet/src/core/Socket.js          |    8 ++++----
 loleaflet/src/layer/tile/TileLayer.js |   13 ++++++++++---
 3 files changed, 46 insertions(+), 7 deletions(-)

New commits:
commit d2459a157aed0699b772ddb3319c7dd70dde26a3
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Thu Jan 14 21:28:10 2016 +0100

    loleaflet: Implement 'id' for errors.
    
    Most of the errors are not interesting for the user, for those return just a
    general 'internal error'; details are still available through the 'cmd' and
    'kind'.

diff --git a/loleaflet/reference.html b/loleaflet/reference.html
index dfe1736..7ac486e 100644
--- a/loleaflet/reference.html
+++ b/loleaflet/reference.html
@@ -2046,6 +2046,12 @@ unexpected behaviour.</h4>
 		<th>description</th>
 	</tr>
 	<tr>
+		<td><code><b>id</b></code></td>
+		<td><code>Number</code></td>
+		<td>Identificator of the error that can be used as indication
+		of error message to present to the user.</td>
+	</tr>
+	<tr>
 		<td><code><b>msg</b></code></td>
 		<td><code>String</code></td>
 		<td>If present, the error message.</td>
@@ -2062,6 +2068,32 @@ unexpected behaviour.</h4>
 	</tr>
 </table>
 
+The <code>id</code> property of ErrorEvent can have the following values:
+
+<table data-id='events'>
+	<tr>
+		<th>value</th>
+		<th>description</th>
+	</tr>
+	<tr>
+		<td><code><b>1</b></code></td>
+		<td>Internal error. Things still may work to some extent, but
+		the session becomes unreliable.</td>
+	</tr>
+	<tr>
+		<td><code><b>2</b></code></td>
+		<td>Document couldn't be loaded.</td>
+	</tr>
+	<tr>
+		<td><code><b>3</b></code></td>
+		<td>Socket connection error.</td>
+	</tr>
+	<tr>
+		<td><code><b>4</b></code></td>
+		<td>Socket connection was closed.</td>
+	</tr>
+</table>
+
 <h3 id="invalidatepreview-event">InvalidatePreviewEvent</h3>
 <p>LOLeaflet specific events.</p>
 
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 716fe00..9c2ab1b 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -4,13 +4,13 @@
 
 L.Socket = L.Class.extend({
 	initialize: function (map) {
+		this._map = map;
 		try {
 			this.socket = new WebSocket(map.options.server);
 		} catch (e) {
-			this.fire('error', {msg: 'Socket connection error'});
+			this._map.fire('error', {msg: 'Socket connection error', cmd: 'socket', kind: 'failed', id: 3});
 			return null;
 		}
-		this._map = map;
 		this._msgQueue = [];
 		this.socket.onerror = L.bind(this._onSocketError, map);
 		this.socket.onclose = L.bind(this._onSocketClose, map);
@@ -159,11 +159,11 @@ L.Socket = L.Class.extend({
 	},
 
 	_onSocketError: function () {
-		this.fire('error', {msg: 'Socket connection error'});
+		this._map.fire('error', {msg: 'Socket connection error', cmd: 'socket', kind: 'failed', id: 3});
 	},
 
 	_onSocketClose: function () {
-		this.fire('error', {msg: 'Socket connection closed'});
+		this._map.fire('error', {msg: 'Socket connection closed', cmd: 'socket', kind: 'closed', id: 4});
 	},
 
 	parseServerCmd: function (msg) {
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 3a88565..9f755bb 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -355,7 +355,14 @@ L.TileLayer = L.GridLayer.extend({
 
 	_onErrorMsg: function (textMsg) {
 		var command = this._map._socket.parseServerCmd(textMsg);
-		this._map.fire('error', {cmd: command.errorCmd, kind: command.errorKind});
+
+		// let's provide some convenience error codes for the UI
+		var errorId = 1; // internal error
+		if (command.errorCmd === 'load') {
+		    errorId = 2; // document cannot be loaded
+		}
+
+		this._map.fire('error', {cmd: command.errorCmd, kind: command.errorKind, id: errorId});
 	},
 
 	_onGetChildIdMsg: function (textMsg) {
@@ -814,7 +821,7 @@ L.TileLayer = L.GridLayer.extend({
 			}
 			this._graphicMarker = L.rectangle(this._graphicSelection, {fill: false});
 			if (!this._graphicMarker) {
-				this._map.fire('error', {msg: 'Graphic marker initialization'});
+				this._map.fire('error', {msg: 'Graphic marker initialization', cmd: 'marker', kind: 'failed', id: 1});
 				return;
 			}
 			this._graphicMarker.editing.enable();
@@ -835,7 +842,7 @@ L.TileLayer = L.GridLayer.extend({
 			}
 			this._cellCursorMarker = L.rectangle(this._cellCursor, {fill: false, color: '#000000', weight: 2});
 			if (!this._cellCursorMarker) {
-				this._map.fire('error', {msg: 'Cell Cursor marker initialization'});
+				this._map.fire('error', {msg: 'Cell Cursor marker initialization', cmd: 'cellCursor', kind: 'failed', id: 1});
 				return;
 			}
 			this._map.addLayer(this._cellCursorMarker);


More information about the Libreoffice-commits mailing list