Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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 :/

share|improve this question
    
Is it good idea to make throwAsDartError(js.Proxy jsError) {throw new Exception("${jsError.code} $jsError.message")} ? –  Bzik Nov 22 '13 at 12:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.