I need to set a timeout in the ionic native http plugins POST function.
I need to display an error when the request is not responded within 30 seconds.
How to do it.
import {Http, Headers} from '@angular/http';
import 'rxjs/add/operator/timeout'; // Don't forget this import, otherwise not gonna work
let headers: Headers = new Headers();
headers.append('Content-Type', 'application/json');
let body = {whatever: 'whatever'};
this.http.post(YOUR_URL,
body, {headers: headers})
.timeout(30000)
.map(res => res.json())
.subscribe((something) => {
// Cool
}, (errorResponse: any) => {
// Not cool
});
P.S.: Sorry didn’t saw you were look for ionic native plugin…anyway let me know if that might work in your case otherwise could delete my post as you want
This did not work. It should be different in Ionic Native I think.
Then is it a must in your project to use native http? why not trying with angular http?
@reedrichards
I worked on this a lot but then had to follow your solutons. Angular http workds flawlessly. Anyone should go for it.
1 Like
Sorry that it took too much time but good to hear you found a solution
You can use
this.http.setRequestTimeout(5.0); // seconds
how do subscribe to the event when timed out?