【问题标题】:How do you get the message from PlatformException?如何从 PlatformException 获得消息?
【发布时间】:2021-01-04 01:58:48
【问题描述】:

我在云函数中进行了 https 调用,如果条件失败则抛出错误,在颤振中我成功处理了它,它向我显示:PlatformException(functionsError, Cloud function failed with exception., {code: FAILED_PRECONDITION, details: null,消息:错误:您的卡被拒绝。})

但我想知道如何才能让消息部分显示给用户?到目前为止,我已经尝试过 e.message 但这没有用

CloudFunctions(app: Firebase.app(), region: 'asia-southeast2')
      .getHttpsCallable(functionName: 'addPayment')
      .call({
    'paymentMethodId': paymentMethod.id,
    'userid': FirebaseAuth.instance.currentUser.uid,
  }).catchError((e) => print('ERROR $e'));

这是我的功能

【问题讨论】:

    标签: flutter google-cloud-functions


    【解决方案1】:

    PlatformException class 具有以下属性:

    • code → String 错误代码。最终

    • details → 动态错误详情,可能为空。最终

    • hashCode → int 此对象的哈希码。 [...] 只读, 继承

    • message → String 人类可读的错误消息,可能为空。 最终

    • runtimeType → Type A 表示的运行时类型 目的。只读,继承

    handle it 你会这样做:

    .catchError((e) {
        if (e is PlatformException){
             // Show e.details['message']
        }else{
             print('ERROR $e');
        }
    });
    

    【讨论】:

      猜你喜欢
      • 2011-04-16
      • 1970-01-01
      • 1970-01-01
      • 2018-05-02
      • 2016-08-15
      • 1970-01-01
      • 1970-01-01
      • 2014-10-23
      • 1970-01-01
      相关资源
      最近更新 更多