I am very new at this. I am testing out some apple receipt verification code. I keep getting {"code":141,"error":"success/error was not called"}. If I do "parse log" I can see that the transaction was a success, how do I make that work without an error? I need to do stuff in the success callback?
Parse.Cloud.define("validateReceipt", function(request, response) {
var receipt = '{"receipt-data":"ew0KCSJzaWduYXR1cmUiID0gIkFwTVVCQzg2QWx6TmlrVjVZdHJaQU1pSlFiSzhFZGVYazYza1dCQVh6bEM4ZFhHdWpxNDdabklZS29GRTFvTi9GUzhjWGxGZnA5WVh0OWlNQmRMMjUwbFJSbWlOR2J5aGl0cnlZVkFRb3JpMzJXOWFSMFQ4TC9hWVZCZGZXK095L1F5UFpFbW9OS3hobnQyV05TVURvVWhaOForNHBQNzBwZTVrVVFsYmRJVmhBQUFEVnpDQ0ExTXdnZ0k3b0FNQ0FRSUNDR1VVa1UzWldBUzFNQTBHQ1NxR1NJYjNEUUVCQlFVQU1IOHhDekFKQmdOVkJBWVRBbFZUTVJNd0VRWURWUVFLREFwQmNIQnNaU0JKYm1NdU1TWXdKQVlEVlFRTERCMUJjSEJzWlNCRFpYSjBhV1pwWTJGMGFXOXVJRUYxZEdodmNtbDBlVEV6TURFR0ExVUVBd3dxUVhCd2JHVWdhVlIxYm1WeklGTjBiM0psSUVObGNuUnBabWxqWVhScGIyNGdRWFYwYUc5eWFYUjVNQjRYRFRBNU1EWXhOVEl5TURVMU5sb1hEVEUwTURZeE5ESXlNRFUxTmxvd1pERWpNQ0VHQTFVRUF3d2FVSFZ5WTJoaGMyVlNaV05sYVhCMFEyVnlkR2xtYVdOaGRHVXhHekFaQmdOVkJBc01Fa0Z3Y0d4bElHbFVkVzVsY3lCVGRHOXlaVEVUTUJFR0ExVUVDZ3dLUVhCd2JHVWdTVzVqTGpFTE1Ba0dBMVVFQmhNQ1ZWTXdnWjh3RFFZSktvWklodmNOQVFFQkJRQURnWTBBTUlHSkFvR0JBTXJSakYyY3Q0SXJTZGlUQ2hhSTBnOHB3di9jbUhzOHAvUndWL3J0LzkxWEtWaE5sNFhJ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SW05eWFXZHBibUZzTFhSeVlXNXpZV04wYVc5dUxXbGtJaUE5SUNJeE1EQXdNREF3TURRMk1UYzRPREUzSWpzS0NTSmlkbkp6SWlBOUlDSXlNREV5TURReU55STdDZ2tpZEhKaGJuTmhZM1JwYjI0dGFXUWlJRDBnSWpFd01EQXdNREF3TkRZeE56ZzRNVGNpT3dvSkluRjFZVzUwYVhSNUlpQTlJQ0l4SWpzS0NTSnZjbWxuYVc1aGJDMXdkWEpqYUdGelpTMWtZWFJsTFcxeklpQTlJQ0l4TXpNMU56azRNelUxT0RZNElqc0tDU0p3Y205a2RXTjBMV2xrSWlBOUlDSmpiMjB1YldsdVpHMXZZbUZ3Y0M1a2IzZHViRzloWkNJN0Nna2lhWFJsYlMxcFpDSWdQU0FpTlRJeE1USTVPREV5SWpzS0NTSmlhV1FpSUQwZ0ltTnZiUzV0YVc1a2JXOWlZWEJ3TGsxcGJtUk5iMklpT3dvSkluQjFjbU5vWVhObExXUmhkR1V0YlhNaUlEMGdJakV6TXpVM09UZ3pOVFU0TmpnaU93b0pJbkIxY21Ob1lYTmxMV1JoZEdVaUlEMGdJakl3TVRJdE1EUXRNekFnTVRVNk1EVTZOVFVnUlhSakwwZE5WQ0k3Q2draWNIVnlZMmhoYzJVdFpHRjBaUzF3YzNRaUlEMGdJakl3TVRJdE1EUXRNekFnTURnNk1EVTZOVFVnUVcxbGNtbGpZUzlNYjNOZlFXNW5aV3hsY3lJN0Nna2liM0pwWjJsdVlXd3RjSFZ5WTJoaGMyVXRaR0YwWlNJZ1BTQWlNakF4TWkwd05DMHpNQ0F4TlRvd05UbzFOU0JGZEdNdlIwMVVJanNLZlE9PSI7DQoJImVudmlyb25tZW50IiA9ICJTYW5kYm94IjsNCgkicG9kIiA9ICIxMDAiOw0KCSJzaWduaW5nLXN0YXR1cyIgPSAiMCI7DQp9"}';
Parse.Cloud.httpRequest({
method: 'POST',
url: "https://sandbox.itunes.apple.com/verifyReceipt",
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
body: receipt,
success: function(httpResponse) {
console.log(httpResponse.text);
},
error: function(httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
}
}); });
code 141 is indicative of a script failure, the most common of which is "success/error was not called" that happens when your code flow doesn't lead to a response(funcs)/status(jobs) .success() to return the parameter as a desired result or .error() to throw an exception as a Parse.Error object.
this means success() resolves to the argument passed in, i.e
var response = Parse.Cloud.FunctionResponse.success("some string"); response == "some string";
but with errors, the argument is setting the user message for the error not the result itself, i.e.
var response = Parse.Cloud.FunctionResponse.error("some string"); response == "some string";
a full list of the Parse error codes can be found in ParseException's reference http://parse.com/docs/dotnet/api/html/T_Parse_ParseException_ErrorCode.htm
to check for this exact error, you could always test against the constant provided by Parse to mark Cloud Code scripting errors, i.e (error.code == Parse.Error.SCRIPT_FAILED) https://parse.com/docs/js/symbols/Parse.Error.html#.SCRIPT_FAILED
additionally, you can receive a script error code 141 for any other number of reasons yet all relate to your cloud code, like "Can't call success/error multiple times" that can happen if you don't break out of the flow with return after throwing an error or are not properly waiting for async values before executing dependent functions, be sure to check out the Parse.Promise reference to handle async correctly with the Parse Javascript SDK as all async methods return a Parse.Promise, the .then() method is incredibly simple to navigate the flow with.
Got it had to add the response.