1
0
Fork 0
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:
Joshua Spence 2014-06-05 09:41:46 -07:00 committed by epriestley
parent ba2ce8a5ca
commit 8033a69746
4 changed files with 65 additions and 44 deletions

View file

@ -31,6 +31,10 @@ package {
ExternalInterface.call('JX.Aphlict.didReceiveEvent', type, object); ExternalInterface.call('JX.Aphlict.didReceiveEvent', type, object);
} }
protected function error(error:Error):void {
this.externalInvoke('error', error.toString());
}
protected function log(message:String):void { protected function log(message:String):void {
this.externalInvoke('log', message); this.externalInvoke('log', message);
} }

View file

@ -131,34 +131,38 @@ package {
} }
private function didReceiveSocket(event:Event):void { private function didReceiveSocket(event:Event):void {
var b:ByteArray = this.readBuffer; try {
this.socket.readBytes(b, b.length); var b:ByteArray = this.readBuffer;
this.socket.readBytes(b, b.length);
do { do {
b = this.readBuffer; b = this.readBuffer;
b.position = 0; b.position = 0;
if (b.length <= 8) { if (b.length <= 8) {
break; 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);
} }
} else {
break; var msg_len:Number = parseInt(b.readUTFBytes(8), 10);
} if (b.length >= msg_len + 8) {
} while (true); 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);
}
} }
} }

View file

@ -24,25 +24,39 @@ JX.behavior('aphlict-listen', function(config) {
// Respond to a notification from the Aphlict notification server. We send // Respond to a notification from the Aphlict notification server. We send
// a request to Phabricator to get notification details. // a request to Phabricator to get notification details.
function onaphlictmessage(type, message) { function onaphlictmessage(type, message) {
if (type == 'receive') { switch (type) {
var routable = new JX.Request('/notification/individual/', onnotification) case 'error':
.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) : '';
new JX.Notification() new JX.Notification()
.setContent('(Aphlict) [' + type + '] ' + details) .setContent('(Aphlict) ' + message)
.alterClassName('jx-notification-debug', true) .alterClassName('jx-notification-error', true)
.show(); .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 // If the notification affected an object on this page, show a
// permanent reload notification if we aren't already. // permanent reload notification if we aren't already.
if ((response.primaryObjectPHID in config.pageObjects) && if ((response.primaryObjectPHID in config.pageObjects) && !showing_reload) {
!showing_reload) {
var reload = new JX.Notification() var reload = new JX.Notification()
.setContent('Page updated, click to reload.') .setContent('Page updated, click to reload.')
.alterClassName('jx-notification-alert', true) .alterClassName('jx-notification-alert', true)

Binary file not shown.