有没有办法在 iOS 上的 React Native 中获取底层 NSURLErrorDomain (代码)?

发布于 2025-01-11 09:00:57 字数 690 浏览 3 评论 0原文

在我们的 React Native 应用程序中,我们使用 TrustKit 在 iOS 上进行证书固定。如果证书验证失败并且我在 JavaScript 上下文中捕获错误(如下例),则记录错误仅显示一般错误消息:TypeError: Network request failed

由于错误不是源于 http 状态代码,例如 404,我相信我需要检查 NSURLErrorDomain 代码(例如)这样我就可以用正确的错误处理来映射它。 React Native、fetchaxios 或其他包中是否有任何 API 可以提供对这些错误详细信息的访问?

fetch(myURL).then(() => true, (error) => {
    console.log(error) //TypeError: Network request failed
    return false;
})

In our React Native app we use TrustKit for certificate pinning on iOS. If the certificate validation fails and I catch the error within the JavaScript context (example below), logging the error only shows a generic error message: TypeError: Network request failed.

Since the error doesn't stem from an http status code, like 404, I believe I need to inspect the NSURLErrorDomain code (for example) so that I can map it with the correct error handling. Are there any APIs in React Native, fetch, axios, or another package that would provide access to these error details?

fetch(myURL).then(() => true, (error) => {
    console.log(error) //TypeError: Network request failed
    return false;
})

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文