Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Handle JSON parsing erros by retrying.

  • Loading branch information...
commit 7cb32b7b30161dfa47c55a04186512aea1d2801f 1 parent c4ca2f7
geremy authored
View
2  flash/3.4/src/PubNubFlexExample.mxml
@@ -34,13 +34,13 @@
[Bindable]
public var origin:String = 'pubsub.pubnub.com';
- //public var origin:String = 'multiplexing.pubnub.com';
[Bindable]
public var pub_key:String = 'demo';
[Bindable]
public var sub_key:String = 'sub-c-3a693cf8-7401-11e2-8b02-12313f022c90';
+ //public var sub_key:String = 'demo';
[Bindable]
public var secret_key:String = '';
View
2  flash/3.4/src/com/pubnub/connection/AsyncConnection.as
@@ -44,7 +44,7 @@ package com.pubnub.connection {
}
private function doSendOperation(operation:Operation):void {
- trace('doSendOperation');
+ //trace('doSendOperation');
clearTimeout(timeout);
timeout = setTimeout(onTimeout, Settings.OPERATION_TIMEOUT, operation);
this.operation = operation;
View
26 flash/3.4/src/com/pubnub/json/PnJSON.as
@@ -8,14 +8,32 @@ import com.pubnub.log.Log;
*
* @author firsoff maxim, support@pubnub.com
*/
- public class PnJSON {
-
- static public function parse(text:String, reviver:Function = null):Object {
+
+public class PnJSON {
+
+ //static var ticker:int;
+
+ static public function parse(text:String, reviver:Function = null):Object {
+ //ticker ||= 0;
+ //ticker++;
+
+ //Log.log(ticker.toString(), Log.DEBUG);
+
+ /// Debug blowup
+
+// if (ticker == 5) {
+// Log.log("**** PNJSON SPLAT!****", Log.DEBUG);
+// trace(new Date() + "**** PnJSON SPLAT!****", Log.DEBUG);
+// var badParse:Object = JSON3dParty.parse('"{:');
+// return badParse;
+// }
+
try {
return JSONNative.parse(text, reviver);
}catch (err:Error) {
- Log.log("PARSE ERROR!", Log.DEBUG);
+ // Log.log("Unable to do native parse.", Log.DEBUG);
}
+
return JSON3dParty.parse(text);
}
View
15 flash/3.4/src/com/pubnub/operation/Operation.as
@@ -1,13 +1,15 @@
package com.pubnub.operation {
+
import com.pubnub.json.PnJSON;
- import com.pubnub.net.URLRequest;
+import com.pubnub.log.Log;
+import com.pubnub.net.URLRequest;
import com.pubnub.net.URLRequestHeader;
import com.pubnub.Settings;
import flash.events.IEventDispatcher;
import flash.net.URLRequestMethod;
import flash.utils.getTimer;
import org.casalib.events.RemovableEventDispatcher;
-
+
/**
* ...
* @author firsoff maxim, firsoffmaxim@gmail.com, icq : 235859730
@@ -64,12 +66,17 @@ package com.pubnub.operation {
try {
result = PnJSON.parse(String(data));
}catch (err:Error) {
- error = true;
+ Log.log("*** Received bad json: " + data, Log.DEBUG);
+ trace(new Date() + "*** Received bad json: " + data, Log.DEBUG);
+ error = true;
}
}
if (error) {
- dispatchEvent(new OperationEvent(OperationEvent.FAULT, { message:'Error JSON parse', id:'-1' } ));
+ Log.log("**** Its bad JSON! SPLAT!****", Log.DEBUG);
+ trace("**** Its bad JSON!****", Log.DEBUG);
+ dispatchEvent(new OperationEvent(OperationEvent.RESULT, result));
+ //dispatchEvent(new OperationEvent(OperationEvent.FAULT, { message:'Error JSON parse', id:'-1' } ));
}else {
dispatchEvent(new OperationEvent(OperationEvent.RESULT, result));
}
View
18 flash/3.4/src/com/pubnub/subscribe/Subscribe.as
@@ -30,7 +30,7 @@ package com.pubnub.subscribe {
protected var _connected:Boolean;
protected var _connectionUID:String;
- protected var _lastToken:String;
+ protected var _lastToken:String;
protected var _reusedToken:String
protected var factory:Dictionary;
protected var _destroyed:Boolean;
@@ -245,12 +245,16 @@ package com.pubnub.subscribe {
doSubscribe();
return;
}
-
- var messages:Array = RESPONSE[0] as Array;
-
- _lastToken = RESPONSE[1];
- var chStr:String = RESPONSE[2];
-
+
+ try {
+ var messages:Array = RESPONSE[0] as Array;
+ _lastToken = RESPONSE[1];
+ var chStr:String = RESPONSE[2];
+ } catch (e) {
+ Log.log("error parsing response: " + e, Log.DEBUG);
+ doSubscribe();
+ }
+
/*
* MX (array.length = 3)
* RESPONSE = [['m1', 'm2', 'm3', 'm4'], lastToken, ['ch1', 'ch2', 'ch2', 'ch3']];
Please sign in to comment.
Something went wrong with that request. Please try again.