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);
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,6 +131,7 @@ package {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function didReceiveSocket(event:Event):void {
|
private function didReceiveSocket(event:Event):void {
|
||||||
|
try {
|
||||||
var b:ByteArray = this.readBuffer;
|
var b:ByteArray = this.readBuffer;
|
||||||
this.socket.readBytes(b, b.length);
|
this.socket.readBytes(b, b.length);
|
||||||
|
|
||||||
|
@ -159,6 +160,9 @@ package {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (true);
|
} while (true);
|
||||||
|
} catch (err:Error) {
|
||||||
|
this.error(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,20 @@ 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':
|
||||||
|
new JX.Notification()
|
||||||
|
.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})
|
.addData({key: message.key})
|
||||||
.getRoutable();
|
.getRoutable();
|
||||||
|
|
||||||
|
@ -34,8 +46,10 @@ JX.behavior('aphlict-listen', function(config) {
|
||||||
.setPriority(250);
|
.setPriority(250);
|
||||||
|
|
||||||
JX.Router.getInstance().queue(routable);
|
JX.Router.getInstance().queue(routable);
|
||||||
} else if (__DEV__) {
|
break;
|
||||||
if (config.debug) {
|
|
||||||
|
default:
|
||||||
|
if (__DEV__ && config.debug) {
|
||||||
var details = message ? JX.JSON.stringify(message) : '';
|
var details = message ? JX.JSON.stringify(message) : '';
|
||||||
|
|
||||||
new JX.Notification()
|
new JX.Notification()
|
||||||
|
@ -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.
Loading…
Reference in a new issue