【问题标题】:Firebase functions: TypeError: functions.https.HttpsError is not a constructorFirebase 函数:TypeError:functions.https.HttpsError 不是构造函数
【发布时间】:2021-10-16 05:02:58
【问题描述】:

在我的 Firebase 可调用函数中,我抛出这样的异常来通知客户端应用程序出现问题:

export const test = functions.https.onCall(async (data, context) => {

  // omitted

  throw new functions.https.HttpsError(
    'unauthenticated',
    'Unauthorized!',
  );

  // omitted

});

这在 Firebase 模拟器中完美运行,http 响应如下所示:

Status Code: 401 Unauthorized

{"error":{"message":"Unauthorized!","status":"UNAUTHENTICATED"}}

当 Firebase 函数也在 GCP 的服务器上执行时,这曾经运行良好,但最近发生了变化。 http 响应(来自 Google Cloud)现在如下所示:

Status Code: 500 

{"error":{"message":"INTERNAL","status":"INTERNAL"}}

当我检查云功能日志时,它报告了这个错误:

2021-08-12T20:35:15.131Z test 3co9g97v0m98 Unhandled error TypeError: functions.https.HttpsError is not a constructor at someFunction (/workspace/lib/callables/test.js:42:15) at processTicksAndRejections (internal/process/task_queues.js:95:5) at async /workspace/lib/callables/test.js:103:22 at async /workspace/node_modules/firebase-functions/lib/common/providers/https.js:322:26
Unhandled error TypeError: functions.https.HttpsError is not a constructor at test(/workspace/lib/callables/test.js:42:15) at processTicksAndRejections (internal/process/task_queues.js:95:5) at async /workspace/lib/callables/test.js:103:22 at async /workspace/node_modules/firebase-functions/lib/common/providers/https.js:322:26

知道发生了什么以及发生了什么变化吗?我按照文档中推荐的方式抛出异常:https://firebase.google.com/docs/functions/callable

这导致的问题是云函数为任何 HttpsError 返回相同的状态代码和消息,所以我无法区分它们中的任何一个。

【问题讨论】:

    标签: typescript firebase exception google-cloud-functions


    【解决方案1】:

    有一个类似的问题,似乎是最新的firebase-functions 包的问题。我现在通过安装firebase-functions@3.14.1 解决了它。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-30
    • 2020-02-19
    • 2017-01-16
    • 2016-11-07
    • 2018-05-11
    • 1970-01-01
    • 1970-01-01
    • 2013-12-25
    相关资源
    最近更新 更多