Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15505] iOS: HttpClient onload event returns responseCode of 0

GitHub Issuen/a
TypeBug
PriorityLow
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 3.1.0, Release 3.1.2, Release 3.1.3, Release 3.2.1
Fix Version/sn/a
ComponentsiOS
Labelsreprod, supportTeam
ReporterMarco Cota
AssigneeUnknown
Created2013-10-16T18:29:07.000+0000
Updated2018-02-28T20:03:14.000+0000

Description

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];
		}

Comments

  1. Lee Morris 2017-06-21

    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

JSON Source