PROBLEM
When using an httpClient connection and this is succesful the event return a response code of 0, when user tries to do a validation of the response code they get a false as they expect a 200 response.
EVENT OUTPUT
[INFO] : {
[INFO] : code = 0;
[INFO] : source = "[object TiNetworkClient]";
[INFO] : success = 1;
[INFO] : type = load;
[INFO] : }
TEST CASE
var w = Ti.UI.createWindow();
var url = "http://www.cotaman.com/return.php?id=200";
var client = Ti.Network.createHTTPClient({
// function called when the response data is available
onload : function(e) {
console.log('success>>>');
console.log(e);
},
// function called when an error occurs, including a timeout
onerror : function(e) {
console.log("error>>>");
console.log(e);
},
timeout : 5000 // in milliseconds
});
// Prepare the connection.
client.open("GET", url);
// Send the request.
client.send();
w.open();
CONSOLE LOG
[INFO] : APP-739978/1.0 (3.1.3.GA.222f4d1)
[INFO] : success>>>
[INFO] : {
[INFO] : code = 0;
[INFO] : source = "[object TiNetworkClient]";
[INFO] : success = 1;
[INFO] : type = load;
[INFO] : }
SDK CODE
As doing a review we found that a 0 response is hard coded in the Titanium SDK on TiNetworkHTTPClientProxy.m
if (hasOnerror && (responseCode >= 400) && (responseCode <= 599))
{
NSMutableDictionary * event = [TiUtils dictionaryWithCode:responseCode message:@"HTTP error"];
[event setObject:@"error" forKey:@"type"];
[self fireCallback:@"onerror" withArg:event withSource:thisPointer];
}
else if(hasOnload)
{
NSMutableDictionary * event = [TiUtils dictionaryWithCode:0 message:nil];
[event setObject:@"load" forKey:@"type"];
[self fireCallback:@"onload" withArg:event withSource:thisPointer];
}
I am able to reproduce this issue with the following environment; iPhone 7 (10.2) Studio 4.9.0.201705302345 Ti SDK 6.1.1.v20170620103414 Appc NPM 4.2.9 Appc CLI 6.2.1 Ti CLI 5.0.13 Alloy 1.9.11 Arrow 2.0.0 Xcode 8.2 (8C38) Node v4.8.2 Java 1.8.0_131