Skip to content

Commit 425669f

Browse files
committed
WebView 오류 처리 개선
결제 진행 중 발생하는 네트워크 오류를 브라우저와 유사하게 처리하도록 개선: - 기본 오류 화면 표시 방지 - iOS/macOS에서 -1005 오류(네트워크 연결 끊김) 무시 - 카드사 앱에서 돌아올 때 폴링 중인 HTTP 요청이 중단되어 발생 - 기타 오류는 사용자에게 알림으로 표시
1 parent cdfcb3b commit 425669f

File tree

1 file changed

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

1 file changed

+17
-1
lines changed

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

Lines changed: 17 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,22 @@ function Payment({ userCode, tierCode, data, loading, callback }: Props) {
129129
ref={webview}
130130
source={webviewSource}
131131
mixedContentMode={'always'}
132+
onError={(event) => {
133+
console.warn('Encountered an error loading page', event.nativeEvent);
134+
// 탐색이 실패하면 react-native-webview는 바로 오류 화면을 표시하려 한다
135+
// 한편 브라우저는 오류를 무시하여 결제를 계속 진행할 수 있는 경우가 있다
136+
// 브라우저의 동작을 따라한다
137+
event.preventDefault();
138+
// Domain=NSURLErrorDomain Code=-1005 Description="The network connection was lost."
139+
// 지속적으로 폴링하는 카드사(현대카드)의 경우 카드사 앱에서 돌아올 때 HTTP 요청이 강제 중단되어 -1005 오류 발생
140+
// 브라우저에서 간헐적으로 자동 리다이렉트가 안 되고 버튼을 누르라고 하는 경우 이 경우이다
141+
// 무시한다
142+
if (Platform.OS === 'ios' || Platform.OS === 'macos' && event.nativeEvent.code === -1005) {
143+
return;
144+
}
145+
// 이외의 경우에는 어떻게 처리해야 할지 확실하지 않지만 우선 알림을 보여 주도록 구현
146+
Alert.alert(`탐색 오류가 발생했습니다\n도메인: ${event.nativeEvent.domain}\n오류 코드: ${event.nativeEvent.code}\n설명: ${event.nativeEvent.description}`);
147+
}}
132148
onLoadEnd={() => {
133149
if (!isWebViewLoaded) {
134150
if (data.pg.startsWith('eximbay')) {

0 commit comments

Comments
 (0)