That error is triggered when there is no connection so the app can’t get the data from my server.
So i simulate this taking off the connection before the http post.
But it doesn’t wait for 10 seconds before to show the error (i.e. waiting data untill 10 seconds before to go to error), instead the error is showed instantly.
Any ideas for this common problem?
I think the problem is your simulation method isn’t valid. The timeout function wouldn’t trigger if there’s no connection to be made, that’s a completely different error unrelated to timeouts.
as @diegomachado said above - inject a deliberate server-side delay. Or connect to a wifi signal that has no access to the server, but the device still maintains a connection.
Ok this will handle the case where the server is giving the response too late.
But what i’m trying to do is also to handle the real case where the server is working as usual but the device doensn’t have the connection.
How to resolve this second situation to keep my device trying for a certain amount of time a http post using the timeout?
Thank you for the support @beck24
You can deal with it in the error handler, or if you want to be proactive you can use the network connection plugin and detect the connection status: http://ionicframework.com/docs/native/network/
I’m trying your first advice, “You can deal with it in the error handler”, i.e. what i was trying to do at my first post but i can’t figure out how because i’m still getting the part console.log('ERROR') not after the time i set in .timeout(10000) but instantly.
This is my code now:
@reedrichards Yes i have import 'rxjs/add/operator/timeout'; on my service.
So with the last code you showed (where i don’t see something different from mine) if you take off the connection, then do the api call, it will wait 10 seconds before the "// Don't do stuffs" will be executed?
Please tell me no because i don’t know what to do if you say yes
Already tried without () => console.log('END') and nothing changed.
Adding .timeout(10000, new Error('Login timeout exceeded')) i get a compile error:
Argument of type 'Error' is not assignable to parameter of type 'IScheduler'. Property 'now' is missing in type 'Error' so i thought it's no more possible to pass a string like that.
I have @ionic/app-scripts : 1.3.7 and no ideas on how to solve this in this moment.