I am writing a log service, in the log service have several log info. if I fetch IP address, it will fetch IP address after some delay, IP address as undefined in the error object.because
logError(response: any): any {
let errors:any;
console.log(response, "log service error");
this.getIP();
error = {
ExceptionMessage: response.message,
ipaddress: this.getIP(),// is undefined
htmlDOM: document.getElementsByTagName("body")
screenShot:another service call,
}
console.log(error, 'logged');
return error;
}
getIP() {
this.getIPAddress().subscribe((res: any) => {
//getting ipaddress
return res.ip;
});
}
getIPAddress() {
return this.httpClient.get("http://api.ipify.org/?format=json");
}
getScreen() {}
O.p: currently it works by using this set timeout solution.Better solution appreciated.
Tried with async and await but it did not work,
logError(response: any): any {
setTimeout(()=>{
let errors:any;
console.log(response, "log service error");
this.getIP();
error = {
ExceptionMessage: response.message,
ipaddress: this.getIP(),// is undefined
htmlDOM: document.getElementsByTagName("body")
screenShot:another service call,
}
console.log(error, 'logged');
return error;
},7000);
return error;
}