Parse.com HTTPRequest {"代码":141,"错误":"未成功/错误被调用"}

时间:2014-05-25 14:57:57

标签: httprequest parse-platform

我很陌生。我正在测试一些苹果收据验证码。我一直在{"代码":141,"错误":"未成功/错误被调用"}。如果我做"解析日志"我可以看到交易是成功的,如何在没有错误的情况下完成这项工作?我需要在成功回调中做些什么?

Parse.Cloud.define("validateReceipt", function(request, response) {
var receipt = '{"receipt-data":"ew0KCSJzaWduYXR1cmUiID0gIkFwTVVCQzg2QWx6TmlrVjVZdHJaQU1pSlFiSzhFZGVYazYza1dCQVh6bEM4ZFhHdWpxNDdabklZS29GRTFvTi9GUzhjWGxGZnA5WVh0OWlNQmRMMjUwbFJSbWlOR2J5aGl0cnlZVkFRb3JpMzJXOWFSMFQ4TC9hWVZCZGZXK095L1F5UFpFbW9OS3hobnQyV05TVURvVWhaOForNHBQNzBwZTVrVVFsYmRJVmhBQUFEVnpDQ0ExTXdnZ0k3b0FNQ0FRSUNDR1VVa1UzWldBUzFNQTBHQ1NxR1NJYjNEUUVCQlFVQU1IOHhDekFKQmdOVkJBWVRBbFZUTVJNd0VRWURWUVFLREFwQmNIQnNaU0JKYm1NdU1TWXdKQVlEVlFRTERCMUJjSEJzWlNCRFpYSjBhV1pwWTJGMGFXOXVJRUYxZEdodmNtbDBlVEV6TURFR0ExVUVBd3dxUVhCd2JHVWdhVlIxYm1WeklGTjBiM0psSUVObGNuUnBabWxqWVhScGIyNGdRWFYwYUc5eWFYUjVNQjRYRFRBNU1EWXhOVEl5TURVMU5sb1hEVEUwTURZeE5ESXlNRFUxTmxvd1pERWpNQ0VHQTFVRUF3d2FVSFZ5WTJoaGMyVlNaV05sYVhCMFEyVnlkR2xtYVdOaGRHVXhHekFaQmdOVkJBc01Fa0Z3Y0d4bElHbFVkVzVsY3lCVGRHOXlaVEVUTUJFR0ExVUVDZ3dLUVhCd2JHVWdTVzVqTGpFTE1Ba0dBMVVFQmhNQ1ZWTXdnWjh3RFFZSktvWklodmNOQVFFQkJRQURnWTB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DQp9"}';

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);
}
}); });

2 个答案:

答案 0 :(得分:4)

必须添加回复。

success: function(httpResponse) {
        console.log(httpResponse.text);
        response.success(httpResponse.text);
    },
error: function(httpResponse) {
    console.error('Request failed with response code ' + httpResponse.status);
    response.error('Request failed with response code ' + httpResponse.status)

答案 1 :(得分:1)

代码141表示脚本失败,其中最常见的是"未调用成功/错误"当你的代码流没有导致响应(funcs)/ status(jobs).success()将参数作为所需结果返回时发生,或者.error()将异常作为Parse.Error对象抛出

这意味着success()解析为传入的参数,即

var response = Parse.Cloud.FunctionResponse.success("some string"); response == "some string";

但有错误,参数是为错误设置用户消息而不是结果本身,即

var response = Parse.Cloud.FunctionResponse.error("some string"); response == "some string";

Parse错误代码的完整列表可以在ParseException的参考http://parse.com/docs/dotnet/api/html/T_Parse_ParseException_ErrorCode.htm

中找到

要检查这个确切的错误,你总是可以测试Parse提供的常量来标记Cloud Code脚本错误,即(error.code == Parse.Error.SCRIPT_FAILED)https://parse.com/docs/js/symbols/Parse.Error.html#.SCRIPT_FAILED

此外,您可以收到脚本错误代码141,原因是任何其他原因,但都与您的云代码有关,例如"无法多次调用成功/错误"如果您在抛出错误后没有退出流并且在执行相关函数之前没有正确等待异步值,则可能会发生这种情况,请务必查看Parse.Promise引用以正确处理异步解析Javascript SDK,因为所有异步方法都返回一个Parse.Promise,.then()方法非常简单,可以用它来导航流。