[TIMOB-1743] Platform Inconsistency: HTTPClient's onerror's e.error is not consistently set for Android and iOS
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Trivial |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2012-08-07T19:52:51.000+0000 |
Affected Version/s | Release 1.7.1 |
Fix Version/s | n/a |
Components | iOS |
Labels | n/a |
Reporter | Jon Alter |
Assignee | Don Thorp |
Created | 2011-04-15T03:01:09.000+0000 |
Updated | 2012-08-07T19:54:32.000+0000 |
Description
Problem
On iOS, the HTTPClient's onerror handler e.error returns a generic message and not what the server is really returning, and on Android e.error gets the custom status description. SO to get past this we should fix Android so that it returns the same generic message, and for iOS and Android, move the custom status description in to a new property: e.statusDescriptionReproduction
Drop the following in an app.js. It will display "FAIL:" and tell you if the server's response is not being utilized.
var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
var label = Ti.UI.createLabel({ color: '#000', text: 'Loading...', textAlign: 'center' });
win.add(label);
win.open();
var client = Ti.Network.createHTTPClient({
onload: function() {
label.text = 'FAIL! onload handler fired for a request that should have errored.';
},
onerror: function(e) {
if (e.statusDescription != 'This is a custom status description for error code 402!') {
label.text = 'FAIL! e.statusDescription != the custom status description for error code 402!';
}
else {
label.text = 'PASS! The e.statusDescription was properly set, and the onerror handler was used.'
}
}
});
client.open('GET', 'http://appc.me/test/SimulateResponse/?code=402');
client.send();
Workaround
There is no workaround, as there is no way to get at the status description from JavaScript at the moment.Associated Helpdesk Ticket
http://appc.me/c/XLD-83444-775Comments
- Anirudh Nagesh 2011-06-14 This error is still reproducible in Titanium 1.7 SDK, iOS 4.3. The link for the sample code is given below. http://www.pastie.org/2069773 - Anirudh Nagesh
- Dawson Toth 2011-07-14 Updated code body and changed reporter to me. Changed customer priority to reflect the pro and enterprise interest in it.
- Dawson Toth 2011-08-09 Updated the example to be significantly more explicit when it fails.
- Dawson Toth 2011-08-09 I'm still seeing this behavior. I updated the example to more clearly draw out the difference between Android and iOS. I also changed this from being a "feature request" -- it's a difference between the platforms that needs to be corrected. Plus, the server is returning something that iOS is ignoring when it constructs the error message.
- Dawson Toth 2011-08-09 Bumped to next release (1.9.0) so that we can flesh out the changes to both platforms that will be necessary.
- Don Thorp 2011-10-11
The error code in the event is not the HTTP error code from the response. It could be null pointer or some other issue.
this.status
contains the HTTP error code and at least on Androidthis.statusText
contains the description of the error. I propose that a new ticket forstatusText
be added for iOS and this ticket closed as invalid. - Blain Hamon 2011-10-13 httpClient's statusText has existed in iOS since August. If anything, this needs documentation.
- Don Thorp 2011-10-19 methods already exist for checking status.
- Jon Alter 2011-10-20
Confirmed working with this.status and this.statusText
Tested with
1.8.0.v20111006001414 iOS Simulator 4.3 Android Emulator 2.2// Example code: var win = Ti.UI.createWindow({ backgroundColor : '#fff' }); var label = Ti.UI.createLabel({ color : '#000', text : 'Loading...', textAlign : 'center' }); win.add(label); win.open(); win.addEventListener('click', function() { var client = Ti.Network.createHTTPClient({ onload : function(e) { Ti.API.info('####ONload#####: '+JSON.stringify(e) ); Ti.API.info('statusText '+this.statusText); Ti.API.info('status '+this.status); label.text = 'FAIL! onload handler fired for a request that should have errored.'; }, onerror : function(e) { Ti.API.info('####ONERROR#####: '+JSON.stringify(e) ); Ti.API.info('statusText '+this.statusText); Ti.API.info('status '+this.status); if(e.statusDescription != 'This is a custom status description for error code 402!') { label.text = 'FAIL! e.statusDescription != the custom status description for error code 402!'; } else { label.text = 'PASS! The e.statusDescription was properly set, and the onerror handler was used.' } } }); client.open('GET', 'http://appc.me/test/SimulateResponse/?code=402'); // client.setTimeout(1); client.send(); });
I/TiAPI ( 285): (kroll$1: app://app.js) [2,3610] ####ONERROR#####: {"error":"This is a custom status description for error code 402!"} I/TiAPI ( 285): (kroll$1: app://app.js) [2,3612] statusText This is a custom status description for error code 402! I/TiAPI ( 285): (kroll$1: app://app.js) [8,3620] status 402
[INFO] ####ONERROR#####: {"source":{},"type":"error"} [INFO] statusText HTTP/1.1 402 This is a custom status description for error code 402! [INFO] status 402