首页 > 解决方案 > Firebase 函数 - HTTP 错误:400,请求有错误

问题描述

我遇到了一个奇怪的问题。

我正在尝试使用 2 wildcards,但我不断收到错误消息:

!功能:未能创建功能 modRemoveReplies

HTTP 错误:400,请求有错误

有趣的是,我有另一个export使用几乎相同的通配符但不会产生错误......

这是我收到错误的代码:

exports.modRemoveReplies = functions.database
  .ref('replies/{parent}/{postId}/flag_delete')
  .onCreate(async (snapshot, context) => {
    console.log("Test")
    return true;
});

但在我的函数文件的前面,我调用这段代码绝对没有错误

exports.removeReply = functions.database
  .ref('replies/{parent}/{postId}/score')
  .onUpdate(async change => {
    const score = change.after.val();
    if (score === -4) {
      return change.after.ref.parent.remove();
    }
  });

它实际上是相同的,所以我明白为什么会出现这个错误......有什么想法吗?上面的错误消息是唯一显示的信息。

编辑:

使用标志运行后,--debug这是输出:

[2019-05-30T20:55:47.156Z] <<< HTTP RESPONSE 400 变化=X-Origin,Referer,Origin,Accept-Encoding,content-type=application/json;charset=UTF-8, date=Thu, 30 May 2019 20:55:43 GMT, server=ESF, cache-control=private, x-xss-protection=0, x-frame-options=SAMEORIGIN, x-content-类型选项=nosniff,alt-svc=quic=":443"; 马=2592000;v="46,44,43,39",接受范围=无,连接=关闭

[2019-05-30T20:55:47.156Z] <<< HTTP 响应正文代码=400,消息=请求有错误,状态=INVALID_ARGUMENT,详细信息=[@type=type.googleapis.com/google.rpc.BadRequest , fieldViolations=[field=runtime, description=Runtime 字段不能为空。]]

标签: javascriptfirebasefirebase-realtime-databasegoogle-cloud-functions

解决方案


就我而言,我不得不改变

export const onRatingCreated = functions.firestore.document('Programs/{programId}/Ratings/').onCreate((doc, context) => {
    // ...
});

对此

export const onRatingCreated = functions.firestore.document('Programs/{programId}/Ratings/{ratingId}').onCreate((doc, context) => {
    // ...
});

因此,以 Document 通配符结尾为我修复了它。


推荐阅读