I am currently using the following code to handle exceptions:
@Injectable()
export class CustomExceptionHandler extends ExceptionHandler {
call(error, stackTrace = null, reason = null) {
console.warn(error);
}
The code works fine, I can see the error in the console. The error is a Response object, defined in @angular/core. However, the error parameter is 'any'. I can't change the error type (e.g. error:Response), because it wont necessarily be a Response object, it could be anything.
I wanted to use (error instanceof Response), but that wont work, because error is a type of object, which makes sense.
UPDATE
So it turns out (error instanceof Response) does work after all. For some reason it doesn't appear to work when you're debugging the typescript using VS Code. I put a watch on it and it always returned false. Maybe it's because i'm not checking at run-time
Anyway, important thing is that in the context of Angular2 Response objects, instanceof will work just fine as they do have a constructor
Thank to @DanSimon for helping to narrow down what was going wrong, and for providing other ways to check the type of an object!