Skip to content

Commit fa66e31

Browse files
huntiefacebook-github-bot
authored andcommitted
Implement Network.loadingFailed (#53023)
Summary: Pull Request resolved: #53023 Changelog: [Internal] Reviewed By: hoxyq Differential Revision: D79555222 fbshipit-source-id: bfbe36edc867b1fc7a44d8e998489ef1d8896331
1 parent ea50245 commit fa66e31

4 files changed

Lines changed: 25 additions & 0 deletions

File tree

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/InspectorNetworkReporter.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ internal object InspectorNetworkReporter {
8282
*/
8383
@JvmStatic external fun reportResponseEnd(requestId: Int, encodedDataLength: Long)
8484

85+
/**
86+
* Report when a network request has failed.
87+
*
88+
* Corresponds to `Network.loadingFailed` in CDP.
89+
*/
90+
@JvmStatic external fun reportRequestFailed(requestId: Int, cancelled: Boolean)
91+
8592
/**
8693
* Store response body preview. This is an optional reporting method, and is a no-op if CDP
8794
* debugging is disabled.

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkEventUtil.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ internal object NetworkEventUtil {
141141
error: String?,
142142
e: Throwable?
143143
) {
144+
if (ReactNativeFeatureFlags.enableNetworkEventReporting()) {
145+
InspectorNetworkReporter.reportRequestFailed(requestId, false)
146+
}
144147
reactContext?.emitDeviceEvent(
145148
"didCompleteNetworkResponse",
146149
buildReadableArray {

packages/react-native/ReactAndroid/src/main/jni/react/jni/InspectorNetworkReporter.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ static std::unordered_map<int, std::string> responseBuffers;
134134
#endif
135135
}
136136

137+
/* static */ void InspectorNetworkReporter::reportRequestFailed(
138+
jni::alias_ref<jclass> /*unused*/,
139+
jint requestId,
140+
jboolean cancelled) {
141+
NetworkReporter::getInstance().reportRequestFailed(
142+
std::to_string(requestId), cancelled);
143+
}
144+
137145
/* static */ void InspectorNetworkReporter::maybeStoreResponseBodyImpl(
138146
jni::alias_ref<jclass> /*unused*/,
139147
jint requestId,
@@ -184,6 +192,8 @@ InspectorNetworkReporter::maybeStoreResponseBodyIncrementalImpl(
184192
InspectorNetworkReporter::reportDataReceivedImpl),
185193
makeNativeMethod(
186194
"reportResponseEnd", InspectorNetworkReporter::reportResponseEnd),
195+
makeNativeMethod(
196+
"reportRequestFailed", InspectorNetworkReporter::reportRequestFailed),
187197
makeNativeMethod(
188198
"maybeStoreResponseBodyImpl",
189199
InspectorNetworkReporter::maybeStoreResponseBodyImpl),

packages/react-native/ReactAndroid/src/main/jni/react/jni/InspectorNetworkReporter.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ class InspectorNetworkReporter
5151
jint requestId,
5252
jlong encodedDataLength);
5353

54+
static void reportRequestFailed(
55+
jni::alias_ref<jclass> /*unused*/,
56+
jint requestId,
57+
jboolean cancelled);
58+
5459
static void maybeStoreResponseBodyImpl(
5560
jni::alias_ref<jclass> /*unused*/,
5661
jint requestId,

0 commit comments

Comments
 (0)