Flutter Web Error: [firebase_functions/internal] internal

Viewed 156

I have a HTTP Callable Cloud Function written in Python that does some calculations and updates some Firestore documents.

It is actually working for both the android emulator and Chrome (Flutter-Web).

Still, I get the following error when I trigger it from Chrome (Flutter-Web):

Instance of '_Future<HttpsCallableResult<dynamic>>'
Error: [firebase_functions/internal] internal
    at Object.throw_ [as throw] (http://localhost:54521/dart_sdk.js:5067:11)
at https_callable_web.HttpsCallableWeb.new.call (http://localhost:54521/packages/cloud_functions_web/https_callable_web.dart.lib.js:45:23)
    at call.throw (<anonymous>)
    at http://localhost:54521/dart_sdk.js:40576:38
    at _RootZone.runBinary (http://localhost:54521/dart_sdk.js:40445:59)
    at _FutureListener.thenAwait.handleError (http://localhost:54521/dart_sdk.js:35374:33)
    at handleError (http://localhost:54521/dart_sdk.js:35947:51)
    at Function._propagateToListeners (http://localhost:54521/dart_sdk.js:35973:17)
    at _Future.new.[_completeError] (http://localhost:54521/dart_sdk.js:35823:23)
    at async._AsyncCallbackEntry.new.callback (http://localhost:54521/dart_sdk.js:35859:31)
    at Object._microtaskLoop (http://localhost:54521/dart_sdk.js:40708:13)
    at _startMicrotaskLoop (http://localhost:54521/dart_sdk.js:40714:13)
    at http://localhost:54521/dart_sdk.js:36191:9

In the GCP Log I do not have any error shown.

This is what I return from the CF return '{"status":"200", "data": "OK"}'

In the chrome developers tools under the Network tab and status I get a CORS error. I did read quite a lot of SO Questions and I did understand that the CORS error is apparently no the real reason of the error.

Also in the same tab (Network) under Headers -> Request Headers there is shown the following Provisional headers are shown, in the Payload the value {data:null} and Response has nothing to show, which is weird since I am returning a "data": "OK".

I am fully confused, since the error thrown: internal error is not leading me anywhere.

1 Answers

I finally fixed it by omitting region() on the cloud function.

My original code:

exports.checkAuth = functions.region("asia-southeast1").https.onCall(async (data, context: functions.https.CallableContext) => {
    return `uid: ${context.auth?.uid ?? "X"} - email: ${context.auth?.token.email ?? "X"}`;
});

I changed it to:

exports.checkAuth = functions.https.onCall(async (data, context: functions.https.CallableContext) => {
    return `uid: ${context.auth?.uid ?? "X"} - email: ${context.auth?.token.email ?? "X"}`;
});

===UPDATE===

The real root cause is the region you specified in the cloud functions and the firebase functions are different, for example in my original code I used:

functions.region("asia-southeast1").https.onCall()

So, when I instantiate firebase functions in main.dart I must do this:

void main() async {

...

final firebaseFunctions = FirebaseFunctions.instanceFor(region: 'asia-southeast1');

...


}
Related