Fetch issue

Hello guys,

On my app I need to use a fetch to get data from the server.
The issue is that when I’m using my Android 4.2.2, the fetch fails.
As an example to test this I’ve used the Fetching JSON example with some console.log():

<App Background="#eee">
	<DockPanel>
		<StatusBarBackground Dock="Top" />
		<BottomBarBackground Dock="Bottom" />
		<ScrollView>
			<Grid ColumnCount="2">
				<JavaScript>
					var Observable = require("FuseJS/Observable");

					var data = Observable();

					fetch('https://gist.githubusercontent.com/petterroea/5ed146454706990ea8386f147d592eff/raw/b157cfed331da3cb88150051ab74aa131022fef8/colors.json')
						.then(function(response) { 
							console.log("1-------------------------------------"); 
							console.log(JSON.stringify(response)); 
							return response.json(); 
						}).then(function(responseObject) { 
							console.log("2-------------------------------------"); 
							console.log(JSON.stringify(responseObject));  
							data.replaceAll(responseObject); 
						}).catch(function(error) { 
							console.log("3-------------------------------------"); 
							console.log("error " + error); 
							return error;
						});

					module.exports = {
						data: data
					};
				</JavaScript>
				<Each Items="{data}">
					<DockPanel Height="120" Margin="10">
						<Panel DockPanel.Dock="Top" Margin="10" Height="30">
							<Rectangle Layer="Background" CornerRadius="10" Color="#fff"/>
							<Text Value="{colorName}" TextAlignment="Center" Alignment="Center" />
						</Panel>

						<Rectangle Layer="Background" CornerRadius="10" Color="{hexValue}"/>
					</DockPanel>
				</Each>
			</Grid>
		</ScrollView>
	</DockPanel>
</App>

This example only fails on the Android version 4.2.2 with this log:

D/OpenGLRenderer(10741): Enabling debug mode 0
D/dalvikvm(10741): create interp thread : stack size=32KB
D/dalvikvm(10741): create new thread
D/dalvikvm(10741): new thread created
D/dalvikvm(10741): update thread list
D/dalvikvm(10741): threadid=12: interp stack at 0x57503000
D/dalvikvm(10741): threadid=12: created from interp
D/dalvikvm(10741): start new thread
D/dalvikvm(10741): threadid=12: notify debugger
D/dalvikvm(10741): threadid=12 (AsyncTask #1): calling run()

I/SurfaceView(10741): Changes: creating=true format=true size=true visible=true left=true top=true mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceSizeChanged=true mVisible=false mRequestedVisible=true
I/SurfaceView(10741): Cur surface: Surface(name=null, identity=-1)
V/SurfaceView(10741): android.view.SurfaceView{42382358 V.E..... ......ID 0,0-800,1280} got resized: w=800 h=1280, cur w=-1 h=-1
I/SurfaceView(10741): New surface: Surface(name=null, identity=134), vis=true, frame=Rect(0, 0 - 800, 1280)
I/SurfaceView(10741): visibleChanged -- surfaceCreated
I/SurfaceView(10741): surfaceChanged -- format=4 w=800 h=1280
I/SurfaceView(10741): surfaceRedrawNeeded
I/SurfaceView(10741): finishedDrawing
V/SurfaceView(10741): Layout: x=0 y=0 w=800 h=1280, frame=Rect(0, 0 - 800, 1280)

V/InputMethodManager(10741): onWindowFocus: com.foreign.Fuse.Android.AppRoot$1{42380568 VFE..... .F....I. 0,0-800,1280} softInputMode=272 first=true flags=#1810100
V/InputMethodManager(10741): START INPUT: com.foreign.Fuse.Android.AppRoot$1{42380568 VFE..... .F....I. 0,0-800,1280} ic=null tba=android.view.inputmethod.EditorInfo@423a47d0 controlFlags=#105
V/InputMethodManager(10741): Starting input: Bind result=InputBindResult{null com.nuance.xt9.input/.IME #56}
I/SurfaceView(10741): Changes: creating=false format=false size=false visible=false left=false top=false mUpdateWindowNeeded=true mReportDrawNeeded=true redrawNeeded=false forceSizeChanged=false mVisible=true mRequestedVisible=true
I/SurfaceView(10741): Cur surface: Surface(name=null, identity=134)
I/SurfaceView(10741): New surface: Surface(name=null, identity=134), vis=true, frame=Rect(0, 0 - 800, 1280)
I/SurfaceView(10741): surfaceRedrawNeeded
I/SurfaceView(10741): finishedDrawing
V/SurfaceView(10741): Layout: x=0 y=0 w=800 h=1280, frame=Rect(0, 0 - 800, 1280)

D/libc-netbsd(10741): getaddrinfo: gist.githubusercontent.com NO result from proxy 
D/libc-netbsd(10741): res_queryN name = gist.githubusercontent.com, class = 1, type = 1

D/libc-netbsd(10741): res_queryN name = gist.githubusercontent.com., class = 1, type = 1

V/InputMethodManager(10741): focusOut: com.foreign.Fuse.Android.AppRoot$1{42380568 VFE..... ........ 0,0-800,1280} mServedView=com.foreign.Fuse.Android.AppRoot$1{42380568 VFE..... ........ 0,0-800,1280} winFocus=true

V/InputMethodManager(10741): START INPUT: com.foreign.Fuse.Android.AppRoot$1{42380568 VFE..... ......ID 0,0-800,1280} ic=null tba=android.view.inputmethod.EditorInfo@423a84a8 controlFlags=#100
V/InputMethodManager(10741): Starting input: Bind result=InputBindResult{com.android.internal.view.IInputMethodSession$Stub$Proxy@423a8d38 com.nuance.xt9.input/.IME #57}

I/System.out(10741): [CDS][DNS]Unable to resolve host "gist.githubusercontent.com": No address associated with hostname
D/HttpJson(10741): 3-------------------------------------
D/HttpJson(10741): error TypeError: Network request failed

However, in my app, this error also is shown in the device with version 4.4.2.

Has anyone have had any similar issue?

  • Fuse version: v1.5.0 (build 15046)
  • Operating system version: macOS HighSierra 10.13.3
  • The devices I’m using for this test:
  • Asus MemoPad HD 7 with Android 4.2.2
  • Zopo ZP999 with Android 4.4.2
  • OnePlus 3 with Android 8.0
  • Unknown brand/model with Android 5.1.1
  • Samsung Galaxy A5 (2016), Android 7.0

Thanks in advance.

It looks like just a connectivity issue on that device:

I/System.out(10741): [CDS][DNS]Unable to resolve host "gist.githubusercontent.com": No address associated with hostname
D/HttpJson(10741): 3-------------------------------------
D/HttpJson(10741): error TypeError: Network request failed

Not much we can suggest aside from making sure that it indeed does have connectivity and can connect to external resources out on the internet.

Related: your application should handle failing network requests gracefully. If there’s a network problem, tell it to the user.

Hi Uldis, thanks for you reply.

If it was a connectivity problem I wouldn’t make a post… And it would be some kind of coincidence that both devices with Jelly Bean had connectivity issues.

As a matter of fact, the device with Android version 4.4.2 doesn’t return that error:

D/fuse-tim-phone-employee(11508): 3------------------------
D/fuse-tim-phone-employee(11508): {}

As you can see, in this case it returns an empty object.

And to make sure it is not a problem with connectivity:

$ adb shell
shell@android:/ $ ping www.fusetools.com
PING www.fusetools.com (104.20.31.177) 56(84) bytes of data.
64 bytes from 104.20.31.177: icmp_seq=1 ttl=60 time=7.24 ms
64 bytes from 104.20.31.177: icmp_seq=2 ttl=60 time=8.50 ms
64 bytes from 104.20.31.177: icmp_seq=3 ttl=60 time=4.82 ms
64 bytes from 104.20.31.177: icmp_seq=4 ttl=60 time=4.87 ms
64 bytes from 104.20.31.177: icmp_seq=5 ttl=60 time=4.85 ms
^C

In my app I have all possible errors from the server handled gracefully, but users with devices with Jelly Bean (version 4.1 and above) can’t use the app, because to access the contents they have to login, and it fails right there, not always with the “Network request failed” message.

Could you try changing the console.log() line in the catch block to this?

console.log("error " + error.message);

Since you are hitting the error case, this should give you a better explanation on why.

Hello,

I’ve figured out this problem. It is not a Fuse issue or device issue, it’s an Android thing. I will try to explain what I found out, just in case someone gets this behaviour.

I saw the logcat with fresh eyes and found some weird stuff, like NativeCrypto_SSL_do_handshake exception => 0 and CertificateException:java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

So, after a while searching for what could cause this, I figured out that the Android’s API’s < 21 are not supported anymore, so there are no security patches, so there are no updates of the certificates CA. Because of this, the certificates from my application api didn’t validate against the certificates in my (unsupported) devices.

To prove this, I downloaded the certificate and installed it on my device, and the issue with the fetch was gone.

I hope I’ve explained myself in a way that people may understand and maybe this will be helpful to other users.

Thanks for trying to help Uldis.

Thanks for the update and info @Ana – good to know!