mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
refactor(core): remove unused error handler logic (#46216)
There's some old logic in the error handler that tries to read an `ngErrorHandler` property off of the errors that are being logged. As far as I can tell, this is a ViewEngine leftover and it isn't actually being used anywhere. PR Close #46216
This commit is contained in:
committed by
Alex Rickabaugh
parent
d981aabfcf
commit
8fb737cfa4
@@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {getErrorLogger, getOriginalError} from './util/errors';
|
||||
import {getOriginalError} from './util/errors';
|
||||
|
||||
/**
|
||||
* Provides a hook for centralized exception handling.
|
||||
@@ -41,13 +41,10 @@ export class ErrorHandler {
|
||||
|
||||
handleError(error: any): void {
|
||||
const originalError = this._findOriginalError(error);
|
||||
// Note: Browser consoles show the place from where console.error was called.
|
||||
// We can use this to give users additional information about the error.
|
||||
const errorLogger = getErrorLogger(error);
|
||||
|
||||
errorLogger(this._console, `ERROR`, error);
|
||||
this._console.error('ERROR', error);
|
||||
if (originalError) {
|
||||
errorLogger(this._console, `ORIGINAL ERROR`, originalError);
|
||||
this._console.error('ORIGINAL ERROR', originalError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
*/
|
||||
|
||||
export const ERROR_ORIGINAL_ERROR = 'ngOriginalError';
|
||||
export const ERROR_LOGGER = 'ngErrorLogger';
|
||||
|
||||
|
||||
export function wrappedError(message: string, originalError: any): Error {
|
||||
const msg = `${message} caused by: ${
|
||||
@@ -21,11 +19,3 @@ export function wrappedError(message: string, originalError: any): Error {
|
||||
export function getOriginalError(error: Error): Error {
|
||||
return (error as any)[ERROR_ORIGINAL_ERROR];
|
||||
}
|
||||
|
||||
export function getErrorLogger(error: unknown): (console: Console, ...values: any[]) => void {
|
||||
return error && (error as any)[ERROR_LOGGER] || defaultErrorLogger;
|
||||
}
|
||||
|
||||
function defaultErrorLogger(console: Console, ...values: any[]) {
|
||||
(<any>console.error)(...values);
|
||||
}
|
||||
|
||||
@@ -716,9 +716,6 @@
|
||||
{
|
||||
"name": "deepForEach"
|
||||
},
|
||||
{
|
||||
"name": "defaultErrorLogger"
|
||||
},
|
||||
{
|
||||
"name": "defaultScheduler"
|
||||
},
|
||||
|
||||
@@ -728,9 +728,6 @@
|
||||
{
|
||||
"name": "deepForEach"
|
||||
},
|
||||
{
|
||||
"name": "defaultErrorLogger"
|
||||
},
|
||||
{
|
||||
"name": "defaultIterableDiffersFactory"
|
||||
},
|
||||
|
||||
@@ -701,9 +701,6 @@
|
||||
{
|
||||
"name": "deepForEach"
|
||||
},
|
||||
{
|
||||
"name": "defaultErrorLogger"
|
||||
},
|
||||
{
|
||||
"name": "defaultIterableDiffersFactory"
|
||||
},
|
||||
|
||||
@@ -995,9 +995,6 @@
|
||||
{
|
||||
"name": "defaultErrorHandler"
|
||||
},
|
||||
{
|
||||
"name": "defaultErrorLogger"
|
||||
},
|
||||
{
|
||||
"name": "defaultIfEmpty"
|
||||
},
|
||||
|
||||
@@ -431,9 +431,6 @@
|
||||
{
|
||||
"name": "deepForEach"
|
||||
},
|
||||
{
|
||||
"name": "defaultErrorLogger"
|
||||
},
|
||||
{
|
||||
"name": "defaultScheduler"
|
||||
},
|
||||
|
||||
@@ -281,9 +281,6 @@
|
||||
{
|
||||
"name": "createTView"
|
||||
},
|
||||
{
|
||||
"name": "defaultErrorLogger"
|
||||
},
|
||||
{
|
||||
"name": "defaultIterableDiffersFactory"
|
||||
},
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import {ErrorHandler} from '../src/error_handler';
|
||||
import {ERROR_LOGGER, wrappedError} from '../src/util/errors';
|
||||
import {wrappedError} from '../src/util/errors';
|
||||
|
||||
class MockConsole {
|
||||
res: any[][] = [];
|
||||
@@ -16,7 +16,6 @@ class MockConsole {
|
||||
}
|
||||
}
|
||||
|
||||
(function() {
|
||||
function errorToString(error: any) {
|
||||
const logger = new MockConsole();
|
||||
const errorHandler = new ErrorHandler();
|
||||
@@ -56,19 +55,4 @@ describe('ErrorHandler', () => {
|
||||
expect(e).toContain('custom');
|
||||
});
|
||||
});
|
||||
|
||||
it('should use the error logger on the error', () => {
|
||||
const err = new Error('test');
|
||||
const console = new MockConsole();
|
||||
const errorHandler = new ErrorHandler();
|
||||
(errorHandler as any)._console = console as any;
|
||||
const logger = jasmine.createSpy('logger');
|
||||
(err as any)[ERROR_LOGGER] = logger;
|
||||
|
||||
errorHandler.handleError(err);
|
||||
|
||||
expect(console.res).toEqual([]);
|
||||
expect(logger).toHaveBeenCalledWith(console, 'ERROR', err);
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user