As Anderoth had suggested I added a few lines of code to automatically retry upon failure and now everything seems to be working (after one failure).
Here’s what I’ve used in case it proves useful to others:
function defaultResponseHandler (event, url, method, listener, params, requestName, retryCount, failureCallback, caller) local count = retryCount or 0 if ( event.isError ) then print( "Network error! Checking for retry") if event.status == -1 then if count \< 3 then count = count + 1 return request(url, method, listener, params, requestName, count, failureCallback, caller) end end print("\*!\* Network error occured and unable to retry",url,requestName,event.status,"\*!\*") if failureCallback ~= nil then failureCallback(caller, "Base network error "..event.status); else -- since a callback hasn't been provided we'll assume that this is a legacy call and so the listener knows how to handle errors, so we pass the event on. print("There was no failure callback provided, event will be passed to listener") listener(event) end else -- everything is in order so go ahead and do your thing. listener(event) end end plainNetworkRequest = \_G.network.request function request (url, method, listener, params, requestName, retryCount, failureCallback, caller) plainNetworkRequest(url, method, function (event) defaultResponseHandler(event, url, method, listener, params, requestName, retryCount, failureCallback, caller) end , params) end -- add this functions to the corona network library \_G.network.request = request
By adding the above code somewhere that it gets run before all of your other requests, ‘network.request’ will automatically retry if the status is ‘-1’ and you wouldn’t need to change any other part of your code. Also please note that I’ve written this code in a module which is why I haven’t marked the functions as ‘local’ and have used ‘_G’ to access Corona’s network library.