firebase / firebase/firebase-js-sdk

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

Open
#3,996 8 comments 0 reactions 0 assignees View on GitHub
api: functions bug
Dominant language
TypeScript
Stars
5.1k
Forks
1k
Avg merge
2d 21h
Merged PRs (30d)
37

Description

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:

```javascript
//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)));
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the HttpsError and httpsCallable entry points described in the issue, then reproduce the behavior using the supplied callable-function and Node.js client snippets. Compare the handling of an "ok" error with the documented expected then() path; done means the caller can receive the supplied response.error information instead of an internal "Response is missing data field" error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.