【问题标题】:How to catch cloud functions onCall functions.https.HttpsError by Flutter with cloud_functions packageFlutter 使用 cloud_functions 包捕获云函数 onCall functions.https.HttpsError
【发布时间】:2020-06-05 14:04:55
【问题描述】:

我正在使用 Flutter cloud_functions 包和云函数。我想在 CloudFunctionsException(客户端)上捕获 functions.https.HttpsError 无论我故意抛出什么,我都无法使用 Flutter 捕获 functions.https.HttpsError。

CloudFunctionsException 的云函数包抛出的functions.https.HttpsError 是否无法捕获?

帮帮我。

云功能

export const sampleFunctions = functions.region(REGION).https.onCall((data, context) => {
    if (!data.hoge) throw new functions.https.HttpsError('failed-precondition', 'some reason');
    return { response: data.fuga };
});

飞镖

  Future<dynamic> sampleFunction() async {
    final _cloudFunctions = CloudFunctions(region: 'asia-northeast1');
    final _sampleFunctions = _cloudFunctions.getHttpsCallable(
      functionName: 'sampleFunctions',
    );

    try {
      final resp = await _sampleFunctions.call(<String, dynamic>{
        'fuga': 'fuga',
      });
      print(resp);
    } on CloudFunctionsException catch (e) {
      print(e.code);
      print(e.message);
    }
  }

【问题讨论】:

    标签: flutter google-cloud-functions


    【解决方案1】:

    在 Dart 文档中有一个 call function implementation。如果你看一下CloudFunctionsException,只有在异常属性code == 'functionsError'时才会抛出。

    使用functions.https.HttpsError,您是来自第一个参数的代码(示例中为'failed-precondition')。不幸的是,HttpError 限制了错误代码的可能值,并且“functionsError”不在list 中。

    所以这样看来是行不通的。

    希望对你有帮助!

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-31
    • 2020-12-01
    • 2019-12-10
    • 2019-09-30
    • 2019-06-27
    • 2020-07-10
    • 2018-12-06
    • 1970-01-01
    相关资源
    最近更新 更多