Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): use promise.reject when fetch res failed #3604

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import com.tencent.mtt.hippy.modules.nativemodules.HippyNativeModuleBase;
import com.tencent.mtt.hippy.runtime.builtins.JSObject;
import com.tencent.vfs.ResourceDataHolder;
import com.tencent.vfs.ResourceDataHolder.TransferType;
import com.tencent.vfs.VfsManager;
import com.tencent.vfs.VfsManager.FetchResourceCallback;
import java.nio.charset.StandardCharsets;
Expand All @@ -54,7 +53,7 @@ public NetworkModule(HippyEngineContext context) {
}

@SuppressWarnings("deprecation")
private void normalizeRequestHeaders(@NonNull HippyMap headers,
protected void normalizeRequestHeaders(@NonNull HippyMap headers,
@NonNull HashMap<String, String> requestHeaders) {
Set<Entry<String, Object>> entrySet = headers.entrySet();
for (Entry<String, Object> entry : entrySet) {
Expand Down Expand Up @@ -82,7 +81,7 @@ private void normalizeRequestHeaders(@NonNull HippyMap headers,
}

@SuppressWarnings("deprecation")
private void normalizeRequest(@NonNull HippyMap request,
protected void normalizeRequest(@NonNull HippyMap request,
@NonNull HashMap<String, String> requestHeaders,
@NonNull HashMap<String, String> requestParams) throws IllegalStateException {
Set<Entry<String, Object>> entrySet = request.entrySet();
Expand All @@ -103,7 +102,7 @@ private void normalizeRequest(@NonNull HippyMap request,
}
}

private void handleFetchResponse(@NonNull ResourceDataHolder dataHolder, Promise promise)
protected void handleFetchResponse(@NonNull ResourceDataHolder dataHolder, Promise promise)
throws IllegalStateException {
JSObject responseObject = new JSObject();
int statusCode = 0;
Expand Down Expand Up @@ -151,12 +150,12 @@ public void fetch(final HippyMap request, final Promise promise) {
try {
normalizeRequest(request, requestHeaders, requestParams);
} catch (Exception e) {
promise.resolve(e.getMessage());
promise.reject(e.getMessage());
return;
}
final String uri = requestParams.get(HTTP_URL);
if (TextUtils.isEmpty(uri)) {
promise.resolve("Get url parameter failed!");
promise.reject("Get url parameter failed!");
return;
}
vfsManager.fetchResourceAsync(uri, requestHeaders, requestParams,
Expand All @@ -168,12 +167,13 @@ public void onFetchCompleted(@NonNull ResourceDataHolder dataHolder) {
try {
handleFetchResponse(dataHolder, promise);
} catch (IllegalStateException e) {
promise.resolve(
"Handle response failed: " + dataHolder.errorMessage);
promise.reject(
"Handle response failed: " + e.getMessage());
}
} else {
promise.resolve(
"Load remote resource failed: " + dataHolder.errorMessage);
String error = TextUtils.isEmpty(dataHolder.errorMessage)
? "Load remote resource failed!" : dataHolder.errorMessage;
promise.resolve(error);
}
dataHolder.recycle();
}
Expand Down
Loading