-1

This is my code to request the sendCode which is to be received by sms. When the number is enter and submitted it crashes and I still do receive the code by sms.

ParseCloud.callFunctionInBackground("sendCode", params, new FunctionCallback<JSONObject>() {
                    public void done(JSONObject response, ParseException e) {
                        progressBar.setVisibility(View.GONE);
                        if (e == null) {
                            Log.d("Cloud Response", "There were no exceptions! " + response.toString());
                            codeUI();
                        } else {
                            Log.d("Cloud Response", "Exception: " + response.toString() + e);
                            Toast.makeText(getApplicationContext(),
                                    "Something went wrong.  Please try again." + e,
                                    Toast.LENGTH_LONG).show();
                            phoneNumberUI();
                        }
                    }
                });

This is my JSON file on the Parse Cloud

if (!phoneNumber || (phoneNumber.length != 10 && phoneNumber.length != 11)) return res.error('Invalid Parameters');
    Parse.Cloud.useMasterKey();
    var query = new Parse.Query(Parse.User);
    query.equalTo('username', phoneNumber + "");
    query.first().then(function(result) {
        var min = 1000; var max = 9999;
        var num = Math.floor(Math.random() * (max - min + 1)) + min;

        if (result) {
            result.setPassword(secretPasswordToken + num);
            result.set("language", language);
            result.save().then(function() {
                return sendCodeSms(phoneNumber, num, language);
            }).then(function() {
                res.success({});
            }, function(err) {
                res.error(err);
            });
2
  • The application crashes during requesting the code by sms. After the app is crashed I do get the code by sms. Commented Jan 11, 2016 at 18:29
  • please provide the complete stacktrace. I know You posted it at the question, but this must not be the cause of the exception. So it is necessary to see the full logcat output.. Commented Jan 11, 2016 at 18:52

1 Answer 1

0

The ParseCloud function returns a HashMap hierarchy based on your javascript so you can have your code like the following.

ParseCloud.callFunctionInBackground("sendCode", params, new FunctionCallback<HashMap<String, Object>>() {
    public void done(HashMap<String, Object> response, ParseException e) {
        progressBar.setVisibility(View.GONE);
        if (e == null) {
            Log.d("Cloud Response", "There were no exceptions! " + response.toString());
            Log.d("Cloud Response", response.get("data").toString());
            codeUI();
        } else {
            Log.d("Cloud Response", "Exception: " + response.toString() + e);
            Toast.makeText(getApplicationContext(), "Something went wrong.  Please try again." + e, Toast.LENGTH_LONG).show();
            phoneNumberUI();
        }
    }
});

Then in your javascript you can do for the response...

response.success({ data: "yay" });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.