Firebase functions: TypeError: functions.https.HttpsError is not a constructor

Firebase functions: TypeError: functions.https.HttpsError is not a constructor

在我的 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 Function 在 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 返回相同的状态代码和消息,所以我无法区分它们中的任何一个。

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