I'm making port to JavaScript Parse library. One of functions is get https://parse.com/docs/js/symbols/Parse.Query.html#get
var GameScore = Parse.Object.extend("GameScore");
var query = new Parse.Query(GameScore);
query.get("xWMyZ4YEGZ", {
success: function(gameScore) {
// The object was retrieved successfully.
},
error: function(object, error) {
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and description.
}
});
I have decided to represent it as Future.
class ParseQuery {
js.Proxy jsObj; // Parse.Query()
Future<ParseObject> getById(String objectId) {
final f = new Completer();
returnAsParseObj(foundObj) =>
f.complete(new ParseObject.fromProxy(foundObj));
jsObj.get(objectId, js.map({
"success" : new js.FunctionProxy( (foundObj) {returnAsParseObj(foundObj);}
),
"error" : new js.FunctionProxy( (obj, error) {
//TODO throw Dart error/exception for
// <static> <constant> Parse.Error.OBJECT_NOT_FOUND
})
}));
return f.future;
}
}
QUESTION: What should i do to represent and use Parse.Error in Dart (https://parse.com/docs/js/symbols/Parse.Error.html)?
I was thinking about a function like throwAsDartError(js.Proxy jsError) that is able to recognize jsError and throw it as an dartError.
Problem is that i'm not programmer and i don't know how to do that :/