network.request() timeout error

cool! thx BoarK

I still experience this bug - when error happens during request my listener is never called. It happens both for timeout and for unavailable internet connection.

I am using Version 2013.1135 (2013.6.3) for Mac, testing on iPhone4s (with slow Edge internet connection)

Code sample:

local function myListener(event)    print("Response: " .. event.response) end function scene:createScene( event )     local group = self.view     network.request("https://www.stackmob.com", "GET", myListener, {timeout = 1}) end  

Console output of the device (my listener is never called): 

Jun &nbsp;6 16:41:17 ...[10973] \<Warning\>: ERROR: Error during request, code: -1001, details: The request timed out.

Could you fix it?

Well I couldn’t quite generate a time out.  But I turned off my WiFi and it fired the event handler.

I would suggest filing a bug report.  Maybe timeouts don’t trigger the event handler.  But not having network does trigger it as expected.

Hi!

I can confirm that timeouts do trigger the event handler both in simulator and on device (ios 5.1) with build 1131. Haven’t tried on any other devices yet. Perhaps this bug is isolated to certain ios / corona versions.

Hmm, let me check it all again, maybe I have messed up somewhere…

I think I finally got it - problem was calling event.response in my listener. This results in runtime error, which is not shown on device but is shown in simulator.

Log output from device:

Jun  7 12:37:39 Se temp[11694] <Warning>: ERROR: Error during request, code: -1001, details: The request timed out.

Jun  7 12:37:39 Se temp[11694] <Warning>: In myListener

Jun  7 12:37:39 Se temp[11694] <Warning>: Event table contents: {

      bytesEstimated = 0,

      bytesTransferred = 0,

      isError = true,

      name = “networkRequest”,

      phase = “ended”,

      requestId = <userdata 1>,

      status = -1,

      url = “http://www.google.com

    }

Thanks for assistance!

Notice that event.response is nil when there is a time out or other error.  When you did the:

print("Response: " … event.response)

using concatenation, it created a run time error because you can’t append a nil to a string.  Had you done this instead:

print("Response: ", event.response)

the print statement is smart enough to not output anything or output “nil” (depending on condition) if it’s a parameter.

You can add the following to config.lua to see the runtime errors on the device (they are off by default).

[lua]

application =
{
    showRuntimeErrors = true,        – set to true to popup errors, defaults to false

{

[/lua]

Thanks a lot guys, your help is invaluable!