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.statusDescription
Reproduction
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-775
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
Updated code body and changed reporter to me. Changed customer priority to reflect the pro and enterprise interest in it.
Updated the example to be significantly more explicit when it fails.
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.
Bumped to next release (1.9.0) so that we can flesh out the changes to both platforms that will be necessary.
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.httpClient's statusText has existed in iOS since August. If anything, this needs documentation.
methods already exist for checking status.
Confirmed working with this.status and this.statusText
Tested with
1.8.0.v20111006001414 iOS Simulator 4.3 Android Emulator 2.2