My class constructor calls a promise that connects to a service. How do I trap an error if the connection fails? My call to create the class instance is wrapped in a try catch block, but it doesn't get the error from the promise. Like this...
const client = require('aService')
try{let s = new Service()}
catch(e){console.log(`instance error ${e}`)
class Service{
constructor(){
this.connection = client.login()
.then(){
...
}
.catch(e=>{
console.log(`promise error ${e}`
return e
})
}
The console will log "promise error" but not "instance error", which I need so that I can cleanly handle the class instance failing.
Many thanks