Skip to content

Commit e167a60

Browse files
authored
Merge pull request #267 from portone-io/fix/webview-error-handling
react-native-webview 오류 화면 회피
2 parents cdfcb3b + 688aa08 commit e167a60

File tree

1 file changed

+25
-1
lines changed
  • packages/iamport-react-native/src/components/Payment

1 file changed

+25
-1
lines changed

packages/iamport-react-native/src/components/Payment/index.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { IMPData } from 'iamport-react-native';
22
import { createRef, useEffect, useRef, useState } from 'react';
3-
import { Linking, Platform, View } from 'react-native';
3+
import { Alert, Linking, Platform, View } from 'react-native';
44
import WebView from 'react-native-webview';
55
import type { WebViewSource } from 'react-native-webview/lib/WebViewTypes';
66
import { IMPConst } from '../../constants';
@@ -129,6 +129,30 @@ function Payment({ userCode, tierCode, data, loading, callback }: Props) {
129129
ref={webview}
130130
source={webviewSource}
131131
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+
}}
132156
onLoadEnd={() => {
133157
if (!isWebViewLoaded) {
134158
if (data.pg.startsWith('eximbay')) {

0 commit comments

Comments
 (0)