【问题标题】:how to parse nserror received from stripe如何解析从条带收到的nserror
【发布时间】:2019-04-03 10:35:07
【问题描述】:

你好,当我输入一些错误的卡号时,我收到了这种类型的错误

Error Domain=com.stripe.lib Code=70 "您的卡被拒绝" UserInfo={com.stripe.lib:ErrorMessageKey=您的卡被拒绝。您的 请求处于实时模式,但使用了已知的测试卡。, com.stripe.lib:StripeErrorCodeKey=card_declined, com.stripe.lib:StripeErrorTypeKey=card_error, com.stripe.lib:CardErrorCodeKey=com.stripe.lib:CardDeclined, com.stripe.lib:ErrorParameterKey=, NSLocalizedDescription=你的卡 被拒绝}

我想从以下错误中解析这条消息

您的卡被拒绝。您的请求处于实时模式,但使用了 已知的测试卡。

【问题讨论】:

  • 但我想要这个“你的卡被拒绝了。你的请求处于实时模式,但使用了已知的测试卡。”
  • 查看上述问题中的 lib:ErrorMessageKey
  • 你试过error.localizedDescription吗?
  • 是的,它只给出了消息的标题

标签: swift stripe-payments nserror


【解决方案1】:

您需要将error 转换为NSError,然后您可以访问userInfo 并检查该dictionary 中的所有keys 并提取您想要的任何消息值,

if let error = error as? NSError {
    print(error.userInfo)
    print(error.localizedDescription)
    // Check the userInfo object and extract the messages as error.userInfo["messageKey"]
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-18
    • 2012-04-16
    • 1970-01-01
    • 2016-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-10
    相关资源
    最近更新 更多