mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-18 03:20:59 +01:00
Catch errors that may occur whilst receiving data from the Aphlict server.
Summary: Ref T4324. Currently, if the `AphlictMaster` receives dodgy data from the Aphlict server (invalid JSON, for example) then a syntax error will be thrown and the `AphlictMaster` will die. Instead, catch errors and raise a notification. Test Plan: {F163466} Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: epriestley, Korvin Maniphest Tasks: T4324 Differential Revision: https://secure.phabricator.com/D9380
This commit is contained in:
parent
ba2ce8a5ca
commit
8033a69746
4 changed files with 65 additions and 44 deletions
|
@ -31,6 +31,10 @@ package {
|
|||
ExternalInterface.call('JX.Aphlict.didReceiveEvent', type, object);
|
||||
}
|
||||
|
||||
protected function error(error:Error):void {
|
||||
this.externalInvoke('error', error.toString());
|
||||
}
|
||||
|
||||
protected function log(message:String):void {
|
||||
this.externalInvoke('log', message);
|
||||
}
|
||||
|
|
|
@ -131,34 +131,38 @@ package {
|
|||
}
|
||||
|
||||
private function didReceiveSocket(event:Event):void {
|
||||
var b:ByteArray = this.readBuffer;
|
||||
this.socket.readBytes(b, b.length);
|
||||
try {
|
||||
var b:ByteArray = this.readBuffer;
|
||||
this.socket.readBytes(b, b.length);
|
||||
|
||||
do {
|
||||
b = this.readBuffer;
|
||||
b.position = 0;
|
||||
do {
|
||||
b = this.readBuffer;
|
||||
b.position = 0;
|
||||
|
||||
if (b.length <= 8) {
|
||||
break;
|
||||
}
|
||||
|
||||
var msg_len:Number = parseInt(b.readUTFBytes(8), 10);
|
||||
if (b.length >= msg_len + 8) {
|
||||
var bytes:String = b.readUTFBytes(msg_len);
|
||||
var data:Object = vegas.strings.JSON.deserialize(bytes);
|
||||
var t:ByteArray = new ByteArray();
|
||||
t.writeBytes(b, msg_len + 8);
|
||||
this.readBuffer = t;
|
||||
|
||||
// Send the message to all clients.
|
||||
for (var client:String in this.clients) {
|
||||
this.log('Sending message to client: ' + client);
|
||||
this.send.send(client, 'receiveMessage', data);
|
||||
if (b.length <= 8) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
|
||||
var msg_len:Number = parseInt(b.readUTFBytes(8), 10);
|
||||
if (b.length >= msg_len + 8) {
|
||||
var bytes:String = b.readUTFBytes(msg_len);
|
||||
var data:Object = vegas.strings.JSON.deserialize(bytes);
|
||||
var t:ByteArray = new ByteArray();
|
||||
t.writeBytes(b, msg_len + 8);
|
||||
this.readBuffer = t;
|
||||
|
||||
// Send the message to all clients.
|
||||
for (var client:String in this.clients) {
|
||||
this.log('Sending message to client: ' + client);
|
||||
this.send.send(client, 'receiveMessage', data);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
} catch (err:Error) {
|
||||
this.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,25 +24,39 @@ JX.behavior('aphlict-listen', function(config) {
|
|||
// Respond to a notification from the Aphlict notification server. We send
|
||||
// a request to Phabricator to get notification details.
|
||||
function onaphlictmessage(type, message) {
|
||||
if (type == 'receive') {
|
||||
var routable = new JX.Request('/notification/individual/', onnotification)
|
||||
.addData({key: message.key})
|
||||
.getRoutable();
|
||||
|
||||
routable
|
||||
.setType('notification')
|
||||
.setPriority(250);
|
||||
|
||||
JX.Router.getInstance().queue(routable);
|
||||
} else if (__DEV__) {
|
||||
if (config.debug) {
|
||||
var details = message ? JX.JSON.stringify(message) : '';
|
||||
|
||||
switch (type) {
|
||||
case 'error':
|
||||
new JX.Notification()
|
||||
.setContent('(Aphlict) [' + type + '] ' + details)
|
||||
.alterClassName('jx-notification-debug', true)
|
||||
.setContent('(Aphlict) ' + message)
|
||||
.alterClassName('jx-notification-error', true)
|
||||
.show();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'receive':
|
||||
var routable = new JX.Request(
|
||||
'/notification/individual/',
|
||||
onnotification);
|
||||
|
||||
routable
|
||||
.addData({key: message.key})
|
||||
.getRoutable();
|
||||
|
||||
routable
|
||||
.setType('notification')
|
||||
.setPriority(250);
|
||||
|
||||
JX.Router.getInstance().queue(routable);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (__DEV__ && config.debug) {
|
||||
var details = message ? JX.JSON.stringify(message) : '';
|
||||
|
||||
new JX.Notification()
|
||||
.setContent('(Aphlict) [' + type + '] ' + details)
|
||||
.alterClassName('jx-notification-debug', true)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,8 +77,7 @@ JX.behavior('aphlict-listen', function(config) {
|
|||
|
||||
// If the notification affected an object on this page, show a
|
||||
// permanent reload notification if we aren't already.
|
||||
if ((response.primaryObjectPHID in config.pageObjects) &&
|
||||
!showing_reload) {
|
||||
if ((response.primaryObjectPHID in config.pageObjects) && !showing_reload) {
|
||||
var reload = new JX.Notification()
|
||||
.setContent('Page updated, click to reload.')
|
||||
.alterClassName('jx-notification-alert', true)
|
||||
|
|
Binary file not shown.
Loading…
Reference in a new issue