[go: nahoru, domu]

Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[Android] feature : check bundle_type and report error (#2424)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucky-chen authored and YorkShen committed May 9, 2019
1 parent 0ce90fb commit b5dd77c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions android/sdk/src/main/java/com/taobao/weex/WXHttpListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public void setSDKInstance(WXSDKInstance instance) {
this.instance = instance;
}

protected WXSDKInstance getInstance() {
return instance;
}

@Override
public void onHttpStart() {
if (this.instance != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@
import com.taobao.weex.adapter.URIAdapter;
import com.taobao.weex.base.CalledByNative;
import com.taobao.weex.bridge.WXBridgeManager.BundType;
import com.taobao.weex.common.WXErrorCode;
import com.taobao.weex.common.WXRequest;
import com.taobao.weex.common.WXResponse;
import com.taobao.weex.http.WXHttpUtil;
import com.taobao.weex.utils.WXExceptionUtils;

import java.util.HashMap;

public class RequestHandler {
Expand Down Expand Up @@ -91,6 +94,15 @@ public void onSuccess(WXResponse response) {
String script = new String(response.originalData);
BundType bundleType = WXBridgeManager.getInstance().getBundleType("", script);
String bundleTypeStr = bundleType == null ? "Others" : bundleType.toString();
if ("Others".equalsIgnoreCase(bundleTypeStr) && null != getInstance()){
WXExceptionUtils.commitCriticalExceptionRT(
getInstance().getInstanceId(),
WXErrorCode.WX_KEY_EXCEPTION_NO_BUNDLE_TYPE,
"RequestHandler.onSuccess",
"eagle ->" +WXErrorCode.WX_KEY_EXCEPTION_NO_BUNDLE_TYPE.getErrorMsg(),
null
);
}
nativeInvokeOnSuccess(sNativeCallback, script, bundleTypeStr);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,15 @@ private void invokeCreateInstance(@NonNull WXSDKInstance instance, Script templa
}
return;
} else {
//bad case for js bundle with out bundletype header //vue or rax
WXExceptionUtils.commitCriticalExceptionRT(
instance.getInstanceId(),
WXErrorCode.WX_KEY_EXCEPTION_NO_BUNDLE_TYPE,
"invokeCreateInstance",
WXErrorCode.WX_KEY_EXCEPTION_NO_BUNDLE_TYPE.getErrorMsg(),
null
);

invokeExecJS(instance.getInstanceId(), null, METHOD_CREATE_INSTANCE, args, false);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ public enum WXErrorCode {
WX_RENDER_ERR_TEXTURE_SETBACKGROUND("-9620", "WX_RENDER_ERR_TEXTURE_SETBACKGROUND", ErrorType.NATIVE_ERROR, ErrorGroup.NATIVE),


WX_KEY_EXCEPTION_NO_BUNDLE_TYPE("-9801", "Fatal Error : No bundle type in js bundle head, cause white screen or memory leak!!", ErrorType.JS_ERROR, ErrorGroup.JS),
/**
* degrade code.
*/
Expand Down

0 comments on commit b5dd77c

Please sign in to comment.