I need to check if the api is active. Basically I am trying to check if the request status is equal to 0; if it is, I know that the api is off the air.
But I wanted to put this method in my service class and only return true or false to whoever uses it, without having to call a subscrible and do the checks.
verificarServer(): Observable<boolean> {
return this.http.get('http://' + this.HOST + ':' + this.PORT + '/' + this.API).subscribe(
s => { },
e => {
if(e.status == 0){
}else{
}
}
);
}
This is a code I'm trying, it would be something more or less that I would need. Something that returns me true or false in an observable.
How could I solve this?
Edit1
The code using the map does not work (example of this response )
I'm using http from HttpClient
this.http.get('http://' + this.HOST + ':' + this.PORT + '/' + this.API).map((response:Response)=>{
console.log("imprime alguma coisa aqui Cara#$*&¨#*");
console.log(response.status);
});
does not fall within the function map