【问题标题】:Why `functions.https.HttpsError` is not shown in the Firebase function logs?为什么 Firebase 函数日志中不显示 `functions.https.HttpsError`?
【发布时间】:2019-10-14 05:36:59
【问题描述】:

我的可调用 Firebase 函数引发错误:

throw new functions.https.HttpsError(
        'invalid-argument',
        `Invalid token ${token} for file ${fileName}.`
      );

我只看到以下日志:

12:29:22.500 PM SQR-cancelAllotment Function execution took 1779 ms, finished with status code: 400
12:29:20.722 PM SQR-cancelAllotment Function execution started

因此,代码400 没有任何错误消息。为什么?

我不想在单独的console.error 中复制错误消息。

【问题讨论】:

    标签: firebase google-cloud-functions error-logging


    【解决方案1】:

    抛出 HttpsError 是向客户端发出的信号,表明该函数未按预期工作。这并不表示该函数因崩溃而终止(将被记录)。当您抛出 HttpsError 时,如果您想在日志中看到一条消息,您还应该调用 console.error()(或您想要的任何日志级别)以显示该消息。

    【讨论】:

    • 谢谢。那么它是HttpsError 的设计吗?对我来说,如果在finished with status code: 400 之后显示实际消息,那将是合乎逻辑的。是否值得提出功能请求?
    • 随时欢迎您提出功能请求。 support.google.com/firebase/contact/support
    【解决方案2】:

    对于在 Cloud Functions 中引发错误,您可以使用 Stackdriver Error Reporting client libraries

    在这里你可以找到documentation 来设置错误报告(你也有一些例子)

    【讨论】:

    • 谢谢安德烈,不过console.error 足以从函数中记录日志。我的问题是为什么没有自动记录HttpsError 消息。
    • 我明白了。因为它不是要记录的 Cloud Functions 系统中的实际错误或崩溃。比方说,这或多或少是有意的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-10
    • 2019-01-20
    • 1970-01-01
    • 2019-09-09
    • 1970-01-01
    • 1970-01-01
    • 2019-09-22
    相关资源
    最近更新 更多