Commit b400d928 authored by kelvinp's avatar kelvinp Committed by Commit bot

It2MeHelperChannel error reporting cleanup

This CL introduces a new message type - Error. All error
message can only be reported in messages with this type.
This will provide a consistent error reporting mechanism with It2MeHelpeeChannel

Review URL: https://codereview.chromium.org/547013002

Cr-Commit-Position: refs/heads/master@{#293837}
parent 7563b7e3
...@@ -119,7 +119,8 @@ remoting.It2MeHelperChannel.HangoutMessageTypes = { ...@@ -119,7 +119,8 @@ remoting.It2MeHelperChannel.HangoutMessageTypes = {
HELLO: 'hello', HELLO: 'hello',
HELLO_RESPONSE: 'helloResponse', HELLO_RESPONSE: 'helloResponse',
CONNECT: 'connect', CONNECT: 'connect',
DISCONNECT: 'disconnect' DISCONNECT: 'disconnect',
ERROR: 'error'
}; };
/** @enum {string} */ /** @enum {string} */
...@@ -167,11 +168,7 @@ remoting.It2MeHelperChannel.prototype.onHangoutMessage_ = function(message) { ...@@ -167,11 +168,7 @@ remoting.It2MeHelperChannel.prototype.onHangoutMessage_ = function(message) {
throw new Error('Unknown message method=' + message.method); throw new Error('Unknown message method=' + message.method);
} catch(e) { } catch(e) {
var error = /** @type {Error} */ e; var error = /** @type {Error} */ e;
console.error(error); this.sendErrorResponse_(this.hangoutPort_, error, message);
this.hangoutPort_.postMessage({
method: message.method + 'Response',
error: error.message
});
} }
return false; return false;
}; };
...@@ -280,11 +277,7 @@ remoting.It2MeHelperChannel.prototype.onWebappMessage_ = function(message) { ...@@ -280,11 +277,7 @@ remoting.It2MeHelperChannel.prototype.onWebappMessage_ = function(message) {
throw new Error('Unknown message method=' + message.method); throw new Error('Unknown message method=' + message.method);
} catch(e) { } catch(e) {
var error = /** @type {Error} */ e; var error = /** @type {Error} */ e;
console.error(error); this.sendErrorResponse_(this.webappPort_, error, message);
this.webappPort_.postMessage({
method: message.method + 'Response',
error: error.message
});
} }
return false; return false;
}; };
...@@ -309,3 +302,25 @@ remoting.It2MeHelperChannel.prototype.unhookPorts_ = function() { ...@@ -309,3 +302,25 @@ remoting.It2MeHelperChannel.prototype.unhookPorts_ = function() {
this.onDisconnectCallback_ = null; this.onDisconnectCallback_ = null;
} }
}; };
/**
* @param {chrome.runtime.Port} port
* @param {string|Error} error
* @param {?{method:string, data:Object.<string,*>}=} opt_incomingMessage
* @private
*/
remoting.It2MeHelperChannel.prototype.sendErrorResponse_ =
function(port, error, opt_incomingMessage) {
if (error instanceof Error) {
error = error.message;
}
console.error('Error responding to message method:' +
(opt_incomingMessage ? opt_incomingMessage.method : 'null') +
' error:' + error);
port.postMessage({
method: remoting.It2MeHelperChannel.HangoutMessageTypes.ERROR,
message: error,
request: opt_incomingMessage
});
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment