networkListener question!

when i try to download an image from my server, if that image don’t exist, it still passes

the networkListener listner (event.isError  is not trigged). i used corona example:

local function networkListener( event ) if ( event.isError ) then print( "Network error!" ) elseif ( event.phase == "began" ) then if ( event.bytesEstimated \<= 0 ) then print( "Download starting, size unknown" ) else print( "Download starting, estimated size: " .. event.bytesEstimated ) end elseif ( event.phase == "progress" ) then if ( event.bytesEstimated \<= 0 ) then print( "Download progress: " .. event.bytesTransferred ) else print( "Download progress: " .. event.bytesTransferred .. " of estimated: " .. event.bytesEstimated ) end elseif ( event.phase == "ended" ) then print( "Download complete, total bytes transferred: " .. event.bytesTransferred ) end end local params = {} -- Tell network.request() that we want the "began" and "progress" events: params.progress = "download" -- Tell network.request() that we want the output to go to a file: params.response = { filename = "corona.jpg", baseDirectory = system.DocumentsDirectory } network.request( "http://docs.coronalabs.com/images/simulator/image-mask-base2.png", "GET", networkListener, params )

is this behavior normal?

  1.  I notice you put an exclamation point (!) on a lot of your post titles.  That is actually likely to get you fewer answers.  Please focus on forming a useful title instead of an urgent title.  The value of the title is to help people quickly determine if they might be able to help without reading the full post first.  

  2. Yes, I’m pretty sure that is normal.  the .isError flag is to indicate if some error occurred in the execution of the request (usually due to a malformed address or other error in transmission).  

I think un-returned requests simply fall on the floor.  

I suggest this:

  • Modify your listener as follows:

    local function networkListener( event ) for k,v in pairs( event ) d print(k,v) end if ( event.isError ) then

  • Request a image you know is NOT there.

I don’t expect you to see anything new, but just in case, it is always a good idea to explore all possible event response in a case like this.  Maybe, you’re getting back some other indicator of an error.

Finally, I’m afraid while  did a lot of this earlier this year (networking and image requests), my memory is a bit fuzzy right now on the ‘couldn’t find image case’.  Again however, I think it just falls on the floor.  (No response)

.isError will be true only if the request can’t connect to a server, such as it doesn’t exist, or times out. If it makes a successful HTTP request regardless of the results of the request, .isError will be true.

You need to look at event.status. You will find a string that’s really a number, like 200, 301, 404, 500, etc. These status codes indicate the result of the request. 200 is success, 404 if page not found (likely the code if the file you are trying to download doesn’t exist), 500 is a request the server couldn’t make any sense of. 301 is a redirect.

Rob

thanks for both replies. this was not really a question (thats why i used “!”. to me “!” means exclamation, not warning or urgent, my bad if i misslead)  because i solved my problem with a check error 404 as rob suggested.

i was wondering what .isError really do or if there where some hidden feature that i was not aware of, that simplify the process to verify if a file was downloaded or not.

Thanks Rob for the clarification.

thanks roaminggamer for your tips, i done exactly that to solve my problem.

@carloscosta,

I’m glad you got a proper answer on this, thanks to Rob.  I had indeed forgotten about checking event.status.  

Re: exclamation points… yeah that was me being a little grumpy but also trying to help.  Sigh.  I think that was my first answer of the day.  Perhaps my coffee hadn’t kicked in yet.

Again, glad you got a useful answer.

PS - I think if the forums had a badge for ‘grumpy’, it would be near my picture. :slight_smile:

lol, not taken as an offence, don’t worry. i know your comments are for helping people, and you are doing a great job. keep the good work. same applies to Rob.

  1.  I notice you put an exclamation point (!) on a lot of your post titles.  That is actually likely to get you fewer answers.  Please focus on forming a useful title instead of an urgent title.  The value of the title is to help people quickly determine if they might be able to help without reading the full post first.  

  2. Yes, I’m pretty sure that is normal.  the .isError flag is to indicate if some error occurred in the execution of the request (usually due to a malformed address or other error in transmission).  

I think un-returned requests simply fall on the floor.  

I suggest this:

  • Modify your listener as follows:

    local function networkListener( event ) for k,v in pairs( event ) d print(k,v) end if ( event.isError ) then

  • Request a image you know is NOT there.

I don’t expect you to see anything new, but just in case, it is always a good idea to explore all possible event response in a case like this.  Maybe, you’re getting back some other indicator of an error.

Finally, I’m afraid while  did a lot of this earlier this year (networking and image requests), my memory is a bit fuzzy right now on the ‘couldn’t find image case’.  Again however, I think it just falls on the floor.  (No response)

.isError will be true only if the request can’t connect to a server, such as it doesn’t exist, or times out. If it makes a successful HTTP request regardless of the results of the request, .isError will be true.

You need to look at event.status. You will find a string that’s really a number, like 200, 301, 404, 500, etc. These status codes indicate the result of the request. 200 is success, 404 if page not found (likely the code if the file you are trying to download doesn’t exist), 500 is a request the server couldn’t make any sense of. 301 is a redirect.

Rob

thanks for both replies. this was not really a question (thats why i used “!”. to me “!” means exclamation, not warning or urgent, my bad if i misslead)  because i solved my problem with a check error 404 as rob suggested.

i was wondering what .isError really do or if there where some hidden feature that i was not aware of, that simplify the process to verify if a file was downloaded or not.

Thanks Rob for the clarification.

thanks roaminggamer for your tips, i done exactly that to solve my problem.

@carloscosta,

I’m glad you got a proper answer on this, thanks to Rob.  I had indeed forgotten about checking event.status.  

Re: exclamation points… yeah that was me being a little grumpy but also trying to help.  Sigh.  I think that was my first answer of the day.  Perhaps my coffee hadn’t kicked in yet.

Again, glad you got a useful answer.

PS - I think if the forums had a badge for ‘grumpy’, it would be near my picture. :slight_smile:

lol, not taken as an offence, don’t worry. i know your comments are for helping people, and you are doing a great job. keep the good work. same applies to Rob.