I'm currently working on implementing a custom error handling system in Angular using the ErrorHandler
class.
This is what my Globalerror service looks like:
export class CustomErrors extends Error {
button?: any;
errObject: any;
constructor() {
super('custom');
Object.setPrototypeOf(this, CustomErrors.prototype);
}
}
@Injectable()
export class GlobalErrorHandler implements ErrorHandler {
// constructor(private injector: Injector) {}
constructor() {}
handleError(error: any) {
console.log('custom error', error instanceof CustomErrors);
}
}
In the component I'm testing:
ngOnInit() {
try {
throw new Error('error on do the thing');
}
catch (err) {
const errs = new CustomErrors();
//console.log('in service', errs instanceof CustomErrors);
errs.button = 'Back to the start';
throw err;
}
}
However, the console message in the handleError function
console.log('custom error', error instanceof CustomErrors);
always returns false
.
I'm puzzled as to why it's not returning true.