Hey there, I'm currently developing a web application using Angular 2 and I'm focusing on implementing an exception handling mechanism. To achieve this, I've created a model that mirrors the object structure I will receive from the server (ERROR DTO).
Below is the code snippet for my error handler:
protected handleError(error, continuation: () => Observable<any>) {
if (error.status == 401) {
this.appContextService.redirectForLogin();
}
else if (typeof error == ErrorDTO) {
return Observable.throw(error);
}
else {
return Observable.throw(error);
}
}
It's important to note that APIs may throw objects other than my designated ErrorDTO. I need to account for this scenario in my error handling. The issue lies with the second 'else' statement where I check if typeof error == ErrorDTO, it doesn't seem to be working. I want to verify if the error DTO being received matches the type of ErrorDTO. The current implementation throws an error stating "Operator == cannot be applied to types string and type of error DTO." Could someone provide guidance on how to rectify this? Thank you.