Skip to content

Throwing HttpsError('ok') leads to internal exception in httpsCallable #3996

Open
@alex-roboto

Description

@alex-roboto

Yes. Doug Stevenson suggested I file a bug.

[REQUIRED] Describe your environment

  • Operating System version: Windows 10
  • Browser version: N/A (Using Node.js)
  • Firebase SDK version: "firebase-admin": "^8.13.0",
  • Firebase Product: Functions

[REQUIRED] Describe the problem

When a deployed, callable Firebase Function raises an HttpsError with error code "ok" the HttpsCallable on the caller receives an error with code "internal" and the message: "Response is missing data field."

Steps to reproduce:

  1. Deploy a callable Firebase Function that raises httpsError("ok");
  2. Call that function from a client using Node.js and HttpsCallable.
  3. Notice HttpsCallable's catch() gets triggered, with error containing: {"message":"Response is missing data field.","code":"internal"}. The documentation for HttpsError implies that "ok" should set the status to 200 and set response.error.
  4. Expected: HttpsCallable triggers the then() code path, with response.error containing the message given to httpsError.
  5. Guess: My guess is that HttpsError sets status to 200 and sets response.error. However, httpsCallable assumes that all 200's must have response.data set, so an exception is raised on the client. Unfortunately, this makes httpsError("ok") useless as there's no way to access any more information or distinguish httpsError("ok") from any other unhandled exceptions.

Relevant Code:

//Firebase function
exports.UpdateLobby = functions.https.onCall(async (data, context) => {
    throw new functions.https.HttpsError('ok', 'test', 'test2');
}
//Node.js client code
var testFirebaseFunction = firebase.functions().httpsCallable("UpdateLobby");
return testFirebaseFunction().then(function(result) {
    console.log(JSON.stringify(result));
    return;
}).catch(function(error) {
    console.log(JSON.stringify(error, Object.getOwnPropertyNames(error)));
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions