@Injectable()
class MyErrorHandler implements ErrorHandler {
handleError(error) {
// exception occured in some service class method.
console.log('Error in MyErrorhandler - %s', error);
if(error == 'Something went wrong'){
//do this.
}else{
//do this thing.
}
}
}
When in some class' method throws an exception then, the MyErrorHandler class prints the error caught as Error in MyErrorhandler - Error: Uncaught (in promise): [object Object]
Error: Something went wrong.
Question1: Why does the error displays as Error: Uncaught (in promise): [object Object]
?
Question2: Due to the above message it will always read the else part even in the case of if(error == 'Something went wrong')
of the code in any condition.How can I resolve this?
Try adding
if(error.message == 'Something went wrong'){
}
instead of only error. As error is an object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With