Last active
July 16, 2020 14:37
-
-
Save keithstric/3b42acd574e05a13a9b66fa28f9ca66b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class ErrorService { | |
public errorEvent: Subject<Error> = new Subject<any>(); | |
constructor( | |
private _ui: UiService | |
) { } | |
/** | |
* This function is a global javascript error handler. It will catch all javascript errors | |
* produced within the application. The docs at https://angular.io/api/core/ErrorHandler say | |
* that err has a type of any. I'm assuming the "any" type is so you can pass it a custom error | |
* or error event. console logging the err argument just outputs the stack trace. | |
* | |
* @param err {Error} | |
*/ | |
handleError(err: Error) { | |
console.error('ErrorService.handleError, err', err); | |
if (err instanceof EvalError) { | |
// console.log('Error Type=', err.name); | |
}else if (err instanceof RangeError) { | |
// console.log('Error Type=', err.name); | |
}else if (err instanceof ReferenceError) { | |
// console.log('Error Type=', err.name); | |
}else if (err instanceof SyntaxError) { | |
// console.log('Error Type=', err.name); | |
}else if (err instanceof TypeError) { | |
// console.log('Error Type=', err.name); | |
}else if (err instanceof URIError) { | |
// console.log('Error Type=', err.name); | |
}else if (err instanceof ErrorEvent) { | |
// console.log('Error Type=', err.name); | |
}else { | |
// console.log('Error Type=', err.name); | |
} | |
if (DEBUG_DIALOGS) { | |
this._ui.notifyUserShowConfirmDialog({ | |
noCancelButton: true, | |
messageHtml: `<span>${err.message}</span><pre>${err.stack}</pre>`, | |
title: `Error: ${err.name}`, | |
confirmButtonText: 'OK' | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment