|
1 | 1 | import type { IMPData } from 'iamport-react-native'; |
2 | 2 | import { createRef, useEffect, useRef, useState } from 'react'; |
3 | | -import { Linking, Platform, View } from 'react-native'; |
| 3 | +import { Alert, Linking, Platform, View } from 'react-native'; |
4 | 4 | import WebView from 'react-native-webview'; |
5 | 5 | import type { WebViewSource } from 'react-native-webview/lib/WebViewTypes'; |
6 | 6 | import { IMPConst } from '../../constants'; |
@@ -129,6 +129,30 @@ function Payment({ userCode, tierCode, data, loading, callback }: Props) { |
129 | 129 | ref={webview} |
130 | 130 | source={webviewSource} |
131 | 131 | mixedContentMode={'always'} |
| 132 | + onError={(event) => { |
| 133 | + console.warn( |
| 134 | + 'Encountered an error loading page', |
| 135 | + event.nativeEvent |
| 136 | + ); |
| 137 | + // 탐색이 실패하면 react-native-webview는 바로 오류 화면을 표시하려 한다 |
| 138 | + // 한편 별도 설정 안 한 WKWebView는 오류를 무시하여 결제를 계속 진행할 수 있는 경우가 있다 |
| 139 | + // 오류 화면 표시를 막는다 |
| 140 | + event.preventDefault(); |
| 141 | + // Domain=NSURLErrorDomain Code=-1005 Description="The network connection was lost." |
| 142 | + // 지속적으로 폴링하는 카드사(현대카드)의 경우 카드사 앱에서 돌아올 때 HTTP 요청이 강제 중단되어 -1005 오류 발생 |
| 143 | + // 별도 설정 안 한 WKWebView에서 간헐적으로 자동 리다이렉트가 안 되고 버튼을 누르라고 하는 경우 이 경우이다 |
| 144 | + // 무시한다 |
| 145 | + if ( |
| 146 | + Platform.OS === 'ios' || |
| 147 | + (Platform.OS === 'macos' && event.nativeEvent.code === -1005) |
| 148 | + ) { |
| 149 | + return; |
| 150 | + } |
| 151 | + // 이외의 경우에는 어떻게 처리해야 할지 확실하지 않지만 우선 알림을 보여 주도록 구현 |
| 152 | + Alert.alert( |
| 153 | + `탐색 오류가 발생했습니다\n도메인: ${event.nativeEvent.domain}\n오류 코드: ${event.nativeEvent.code}\n설명: ${event.nativeEvent.description}` |
| 154 | + ); |
| 155 | + }} |
132 | 156 | onLoadEnd={() => { |
133 | 157 | if (!isWebViewLoaded) { |
134 | 158 | if (data.pg.startsWith('eximbay')) { |
|
0 commit comments