Skip to content

Instantly share code, notes, and snippets.

@joelklabo
Created December 1, 2010 21:00
Show Gist options
  • Save joelklabo/724215 to your computer and use it in GitHub Desktop.
Save joelklabo/724215 to your computer and use it in GitHub Desktop.
// Returns a wrapped version of the method that returns
// the Error obj to JS-land instead of actually throwing
var genExtFunc:Function = function (func:Function):Function {
return function (...args):* {
try {
for (var arg:* in args){
// Terrible hack working around half baked
// ExternalInterface support provided by
// Safari on Windows
// takes json strings and turns them into objects
if (args[arg] is String){
var o : Object = JSON.decode(args[arg]);
args[arg] = o;
}
}
return func.apply(null, args);
}
catch (e:Error) {
if (e.errorID == 1009){
e.message = "There was a problem with your parameters, " + JSON.encode(args);
}
return e;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment