简体   繁体   English

从 android 应用调用异步 Firebase function 时出现“内部”异常

[英]Getting “INTERNAL” exception when an async Firebase function is called from android app

I'm trying to call an async Firebase function from android app and getting “INTERNAL” exception when the function returns.我正在尝试从 android 应用程序调用异步 Firebase function,并在 function 返回时出现“内部”异常。

Android: Android:

 private Task<String> fetchData() {
    // Create the arguments to the callable function, which is just one string
    Map<String, Object> data = new HashMap<>();
    data.put(“id”, “abc”);

    return FirebaseFunctions.getInstance()
            .getHttpsCallable(“calculate”)
            .call(data)
            .continueWith(new Continuation<HttpsCallableResult, String>() {
                @Override
                public String then(@NonNull Task<HttpsCallableResult> task) throws Exception {
                    Map<String, Object> result = (Map<String, Object>) task.getResult().getData();
                    return (String)result.get(“data”);
                }
            });
 }

Firebase Function: Firebase Function:

exports.calculate = functions.https.onCall((data, context) => {
    const text = data.id;
    return calc.calculate( (err, response) => {
        if(err) {
            // handle error
        } else {
            const data = response.dataValue;
        }
     }).then(() => {
        return {“data”: data};
     });
});

Exception:例外:

com.google.firebase.functions.FirebaseFunctionsException: INTERNAL

The documentation for handling errors in callable functions indicates that an instance of functions.https.HttpsError must be returned: 处理可调用函数中的错误的文档指出必须返回一个函数实例。https.HttpsError:

To ensure the client gets useful error details, return errors from a callable by throwing (or returning a Promise rejected with) an instance of functions.https.HttpsError ... If an error other than HttpsError is thrown from your functions, your client instead receives an error with the message INTERNAL and the code internal. 为了确保客户端获得有用的错误详细信息,请通过抛出(或返回被拒绝的Promise) functions.https.HttpsError实例从可调用functions.https.HttpsError返回错误HttpsError ...如果从函数中抛出了HttpsError以外的错误, HttpsError客户端代替收到错误消息INTERNAL和内部代码。

It seems likely that your calc.calculate() call is returning an error that is not being handled correctly, resulting in a returned error status of INTERNAL. 您的calc.calculate()调用似乎返回了未正确处理的错误,导致返回的错误状态为INTERNAL。

Following the example in the document linked above, your code should be something like: 按照上面链接的文档中的示例,您的代码应类似于:

if(err) {
    // handle error
    throw new functions.https.HttpsError('calc-error', 'some error message');
} else {
    const data = response.dataValue;
}

When you call httpCallable,you will get an exception called FirebaseFunctionsExceptions .当您调用 httpCallable 时,您将得到一个名为FirebaseFunctionsExceptions异常 You have to handled this exceptions.您必须处理此异常。 Wrap your code with try and catch .trycatch包装你的代码。

Example:-例子:-

  try {
      final result = await FirebaseFunctions.instance
            .httpsCallable('deleteUser')
            .call({});
      } on FirebaseFunctionsException catch (error) {
        print(error.message);
      }

For more info follow this link .有关更多信息,请点击此链接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未经授权的错误:Firebase function 从 android 应用调用 - UNAUTHENTICATED ERROR : Firebase function called from android app 防止 android 可调用时应用程序崩溃 firebase function 抛出异常 - Prevent android app crash when callable firebase function throws exception 我的 firebase 可调用云 function 被调用了两次(当我只调用一次时),如何避免我的 flutter 应用程序失败? - My firebase callable cloud function is called twice (when I called only once), how can I avoid my flutter app from failure? onDataChange 在 android Firebase 中被调用两次 - onDataChange is getting called twice in android Firebase 我们如何解决 flutter 应用程序中的 firebase 函数内部异常? - How can we resolve firebase functions INTERNAL exception in a flutter app? 我无法获取异步返回的值 function(firebase 存储) - I can´t Getting a value returned by a async function (firebase storage) Firebase onMessageReceived 在后台应用时未调用 - Firebase onMessageReceived not called when app in background 从我的 vue 应用程序访问 firebase 时,addAuthTokenListener 不是 function - addAuthTokenListener is not a function when accessing firebase from my vue app Firebase 应用程序终止时未调用消息后台处理程序(颤振) - Firebase messaging background handler not called when app is terminated (Flutter) Firebase function 没有在带有 DispatchGroup 的 forEach 循环中被调用 - Firebase function not getting called inside a forEach loop with a DispatchGroup
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM