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

Viewed 379

In my Firebase callable functions, I throw exceptions like this to inform the client app that something went wrong:

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

  // omitted

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

  // omitted

});

This works perfectly in the Firebase emulator, and the http response looks like this:

Status Code: 401 Unauthorized

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

This used to work well when the Firebase Function got executed on GCP's servers as well, but recently that changed. The http response (coming from Google Cloud) now looks like this:

Status Code: 500 

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

When I inspect the cloud function logs, it reports this error:

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

Any idea what's happening and what changed? I'm throwing exceptions the way it's recommended in the docs: https://firebase.google.com/docs/functions/callable

The problem this causes is that the cloud function is returning the same status code and message for any HttpsError, so I'm not able to distinguish between any of them.

1 Answers

Had a similar issue, seems to be a problem with the latest firebase-functions package. I solved it by installed firebase-functions@3.14.1 for now.

Related