[TIMOB-25241] Android: Ti.Network.createHTTPClient log 404 : Not Found error in application log
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2017-11-15T04:28:06.000+0000 |
Affected Version/s | Release 6.2.0 |
Fix Version/s | Release 7.0.0 |
Components | Android |
Labels | android, httpclient |
Reporter | Feon Sua Xin Miao |
Assignee | Gary Mathews |
Created | 2017-09-07T00:08:33.000+0000 |
Updated | 2018-07-12T21:07:14.000+0000 |
Description
*Reproduce Step*
1. create an app
2. add these to
index.js/app.js
function getReadyStateNameFrom(httpClient) {
switch (httpClient.readyState) {
case httpClient.UNSENT: return "UNSENT";
case httpClient.OPENED: return "OPENED";
case httpClient.HEADERS_RECEIVED: return "HEADERS_RECEIVED";
case httpClient.LOADING: return "LOADING";
case httpClient.DONE: return "DONE";
}
return "Unknown";
}
var request = Ti.Network.createHTTPClient({
onload : function() {
console.log('onload: ');
console.log('readyState: ' + getReadyStateNameFrom(request));
},
onerror : function(e) {
console.log('onerror: ', e);
console.log('readyState: ' + getReadyStateNameFrom(request));
}
});
var url = "http://www.appcelerator.com/test.js";
request.open("GET", url);
request.send();
3. run the app
*Actual Output*
iOS
HTTP error responses is returned to the onerror handler
[INFO] onerror: {
[INFO] code = 404;
[INFO] error = "HTTP error";
[INFO] source = "[object TiNetworkHTTPClient]";
[INFO] success = 0;
[INFO] type = error;
[INFO] }
[INFO] readyState: DONE
*Android*
Following output is logged as an eror in the application log.
[ERROR] TiHTTPClient: (TiHttpClient-1) [22,967] HTTP Error (java.io.IOException): 404 : Not Found
[ERROR] TiHTTPClient: java.io.IOException: 404 : Not Found
[ERROR] TiHTTPClient: at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1283)
[ERROR] TiHTTPClient: at java.lang.Thread.run(Thread.java:761)
[INFO] onerror: {"source":{"username":null,"status":404,"location":"http://www.appcelerator.com/test.js","readyState":3,"domain":null,"statusText":"Not Found","validatesSecureCertificate":false,"password":null,"connected":false,"autoEncodeUrl":true,"connectionType":"GET","autoRedirect":true,"responseData":{"height":0,"type":2,"mimeType":"text/html","text":"<!DOCTYPE html>\n<html lang=\"en-US\"\n\titemscope \n\titemtype=\"http://schema.org/WebSite\" \n\tprefix=\"og: http://ogp.me/ns#\" >\n<head>\n\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=Edge,chrome=1\">\n\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n\t<meta charset=\"UTF-8\">\n\t<meta name=\"viewport\" content=\"width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=0\">\n\t<title>Nothing found for Test Js</title>\n\t<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"//fonts.googleapis.com/css?family=Open+Sans:300,400,700,800,400italic,700italic|PT+Sans:400,700|Source+Sans+Pro:200,300,400,600,700\">\n <link href=\"//vjs.zencdn.net/4.12/video-js.css\" rel=\"stylesheet\">\n <script src=\"//vjs.zencdn.net/4.12/video.js\"></script>\n\t <!-- LEGACY STYLES -->\n <link rel=\"stylesheet\" id=\"ss-main\" type=\"text/css\" media=\"all\" href=\"https://www.appcelerator.com/wp-content/themes/appc-rwd/style.css?ver=00717\">\n <link rel=\"stylesheet\" id=\"ss-blog\" type=\"text/css\" media=\"all\" href=\"https://www.appcelerator.com/wp-content/themes/appc-rwd/css/blog.css?ver=00717\">\n\t\n\t<!-- REDESIGN STYLES -->\n <!-- Changing to use wp_enqueue_style() -->\n\t<!--<link rel=\"stylesheet\" id=\"ss-blog\" type=\"text/css\" media=\"all\" href=\"\">-->\n <meta property=\"fb:pages\" content=\"20594753592\" />\n \n\t<link rel=\"shortcut icon\" type=\"image/png\" href=\"https://www.appcelerator.com/wp-content/themes/appc-rwd/img/favicon.ico\">\n\t<link href=\"//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css\" rel=\"stylesheet\">\n\t<link rel=\"stylesheet\" href=\"https://www.appcelerator.com/wp-content/themes/appc-rwd/js/slimbox/css/slimbox2.css\" type=\"text/css\" media=\"screen\" />\n <link rel=\"stylesheet\" href=\"https://www.appcelerator.com/wp-content/themes/appc-rwd/assets/fancybox/jquery.fancybox.css\" type=\"text/css\" media=\"screen\" />\n\t<!--[if IE]><![endif]-->\n\t<!--[if lt IE 9]><script src=\"/assets/js/html5shiv.js\"></script><![endif]-->\n\t\t\n<!-- All in One SEO Pack 2.2.7.5 by Michael Torbert of Semper Fi Web Design[408,448] -->\n<link rel=\"author\" href=\"https://plus.google.com/+appcelerator\" />\n\n<!-- /all in one seo pack -->\n\t\t<script type=\"text/javascript\">\n\t\t\twindow._wpemojiSettings = {\"baseUrl\":\"https:\\/\\/s.w.org\\/images\\/core\\/emoji\\/72x72\\/\",\"ext\":\".png\",\"source\":{\"concatemoji\":\"https:\\/\\/www.appcelerator.com\\/wp-includes\\/js\\/wp-emoji-release.min.js?ver=4.4.1\"}};\n\t\t\t!function(a,b,c){function d(a){var c,d=b.createElement(\"canvas\"),e=d.getContext&&d.getContext(\"2d\");return e&&e.fillText?(e.textBaseline=\"top\",e.font=\"600 32px Arial\",\"flag\"===a?(e.fillText(String.fromCharCode(55356,56806,55356,56826),0,0),d.toDataURL().length>3e3):\"diversity\"===a?(e.fillText(String.fromCharCode(55356,57221),0,0),c=e.getImageData(16,16,1,1).data.toString(),e.fillText(String.fromCharCode(55356,57221,55356,57343),0,0),c!==e.getImageData(16,16,1,1).data.toString()):(\"simple\"===a?e.fillText(String.fromCharCode(55357,56835),0,0):e.fillText(String.fromCharCode(55356,57135),0,0),0!==e.getImageData(16,16,1,1).data[0])):!1}function e(a){var c=b.createElement(\"script\");c.src=a,c.type=\"text/javascript\",b.getElementsByTagName(\"head\")[0].appendChild(c)}var f,g;c.supports={simple:d(\"simple\"),flag:d(\"flag\"),unicode8:d(\"unicode8\"),diversity:d(\"diversity\")},c.DOMReady=!1,c.readyCallback=function(){c.DOMReady=!0},c.supports.simple&&c.supports.flag&&c.supports.unicode8&&c.supports.diversity||(g=function(){c.readyCallback()},b.addEventListener?(b.addEventListener(\"DOMCont
[INFO] readyState: LOADING
*Expected Result*
- Android should *not* log received HTTP response errors (such as 404) to the Android log. Providing the HTTP error response to the onerror() listener is enough, like iOS. (It's up to the app developer to decide to log it.)
- Android *should* set the "readyState" property to "DONE" after receiving HTTP response errors. This is to match our documentation and iOS behavior. (A response was successfully received after all, even though it might not be the response you wanted.)
*Suggested Solution:* Do not throw an exception for HTTP response codes >= 400 here... https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/network/src/java/ti/modules/titanium/network/TiHTTPClient.java#L1282 Instead, let the call to setReadyState(READY_STATE_DONE) happen and dispatch to the appropriate JS onload()/onerror() listener in the Java setReadyState() method.
master: https://github.com/appcelerator/titanium_mobile/pull/9411
Passed FR
Changes are seen in SDK 7.0.0.v20171114203226.
Hi, I am seeing the same happening when using METHOD = HEAD Example Code:
Error in console:
We should not be throwing Exceptions to Android but rather handle in the onError method when using METHOD = HEAD - same as when using METHOD = GET
[~dieskim], would you mind writing that up as a separate ticket please? That way the issue will get in the queue. Thanks.
Ahh... never mind. I see you've already written one up here: [TIMOB-26203]