解析Cloudfunction失败 [英] Parse Cloudfunction fails

查看:127
本文介绍了解析Cloudfunction失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图删除通过云code的文件。
但是,这个脚本会失败:

I'm trying to delete a file through Cloud code. But this script fails:

    Parse.Cloud.define("deleteFile1", function(request, response) {
  Parse.Cloud.httpRequest({
       method: 'DELETE',
       url: 'https://api.parse.com/1/files/****.png',
       headers: {
        "X-Parse-Application-Id": "*******",
        "X-Parse-REST-API-Key" : "*******"
       },
       success: function(httpResponse) {
            console.log('Delete succeeded  ' + httpResponse.text);
        response.success();
       },
       error: function(httpResponse) {
                response.error("failed");
       }
       });
});

,错误141,脚本失败。

with error 141, Script failure.

我把它称为是这样的:

Map<String, String> map = new HashMap<String, String>();
    ParseCloud.callFunctionInBackground("deleteFile1", map, new FunctionCallback<Object>() {
        @Override
        public void done(Object object, ParseException e) {
            if(e == null){

            }else{
                System.out.println(e.getCode());
                utils.toast_error("Couldn't delete image.. try again");
            }

        }
    });

我检查了我的钥匙的,他们是正确的。所以脚本本身一定是错误的以某种方式。我想也许该URL。 IS /文件假设是该图像文件被绑定到ParseFile?我试图改变请求&放大器; 回应HTT presponse等,但它确实没有什么区别。

I've checked my Key's and they are correct. So the script itself must be wrong in some way. I thought maybe the url. Is /files suppose to be the ParseFile which the image file is bound to? I tried changing "request" & "response" to httpResponse etc. But it did no difference.

推荐答案

更新code 现在正常运行,至少,你能捕获错误。

Updated code now runs properly at least, and you are able to catch the error.

您可以的返回实际的消息的修改您的错误处理程序返回 HTT presponse.text

You can return the actual message by modifying your error handler to return the httpResponse.text:

    error: function(httpResponse) {
        response.error("failed " + httpResponse.text);
    }

起初,我用错了 X-解析-REST的API密钥并得到以下错误:

{
    "code": 141,
    "error": "failed {\"error\":\"unauthorized\"}\n"
}

请务必使用键: X-解析-主密钥。那固定在我身边的code和它运行良好。

Make sure to use the MASTER key: X-Parse-Master-Key. That fixed the code on my side and it runs fine.

原文code 失败,因为你不叫成功()上时,它已经完成了你的回应。

Original code failed because you were not calling success() on your response when it has completed.

下面是调用当收到JSON响应 / deleteFile1 ;它表明,这就是问题所在:

Below is the JSON response that is received when calling /deleteFile1; it shows that this is the problem:

{
    code: 141
    error: "success/error was not called"
}

如果你看一下解析云code文档你会看到每个方法使用响应(或在您的code时, HTT presponse )参数和调用 response.success()时,它已经完成了。

If you look at the Parse Cloud Code docs you will see that each method uses the response (or in your code, the httpResponse) parameter and calls response.success() when it has completed.

总是阅读解析发送给您的反应 - 它可以帮助理解的错误

Always read the response that Parse is sending back to you - it may help to understand the error.

中的相关帖子,其中建议同样的事情的答案:

Found related post with answers that suggest the same thing:

  • Parse cloud code giving me Code: 141 error

这篇关于解析Cloudfunction失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆