While working with Angular 2, I encountered an issue when passing an Error object from an HTTP request into the logAndPassOn
method. The error message "Property 'status' does not exist on type 'Error'" was displayed. Although the typeof Error is recognized as an object, it doesn't behave in a similar way to how typeof File would be handled.
private logAndPassOn (error: Error) {
if (error.status == 403) {
// Do things
}
return Observable.throw(error);
}
To work around this problem, I had to set the error's type as 'any'. However, I believe there should be a more optimal solution available. Is there a specific library that needs to be imported for handling the typeof Error? Are there alternative approaches to tackling this issue instead of creating a custom Error class and importing it?