Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Uncaught (in promise): [object Object]

@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?

like image 848
Aditya Avatar asked Oct 03 '17 10:10

Aditya


1 Answers

Try adding

if(error.message == 'Something went wrong'){
}

instead of only error. As error is an object.

like image 110
Kishori Avatar answered Oct 10 '22 17:10

Kishori