gpt4 book ai didi

swift - 如何解析从 strip 接收到的nserror

转载 作者:行者123 更新时间:2023-11-28 05:50:41 25 4
gpt4 key购买 nike

您好,当我输入一些不正确的卡号时出现此类型错误

Error Domain=com.stripe.lib Code=70 "Your card was declined" UserInfo={com.stripe.lib:ErrorMessageKey=Your card was declined. Your request was in live mode, but used a known test card., 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=Your card was declined}

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

Your card was declined. Your request was in live mode, but used a known test card.

最佳答案

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

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

关于swift - 如何解析从 strip 接收到的nserror,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53063392/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com