docs(ExceptionHandler): fix API docs (#11772)

fixes #11769
This commit is contained in:
Victor Berchet 2016-09-23 15:05:43 -07:00 committed by Rado Kirov
parent 9f1c82537e
commit 9be895b6da
1 changed files with 17 additions and 15 deletions

View File

@ -9,18 +9,19 @@
import {WrappedError} from './facade/errors'; import {WrappedError} from './facade/errors';
/** /**
* Provides a hook for centralized exception handling. * @whatItDoes Provides a hook for centralized exception handling.
* *
* The default implementation of `ErrorHandler` prints error messages to the `Console`. To * @description
* intercept error handling, *
* write a custom exception handler that replaces this default as appropriate for your app. * The default implementation of `ErrorHandler` prints error messages to the `console`. To
* intercept error handling, write a custom exception handler that replaces this default as
* appropriate for your app.
* *
* ### Example * ### Example
* *
* ```javascript * ```
*
* class MyErrorHandler implements ErrorHandler { * class MyErrorHandler implements ErrorHandler {
* call(error, stackTrace = null, reason = null) { * handleError(error) {
* // do something with the exception * // do something with the exception
* } * }
* } * }
@ -30,6 +31,7 @@ import {WrappedError} from './facade/errors';
* }) * })
* class MyModule {} * class MyModule {}
* ``` * ```
*
* @stable * @stable
*/ */
export class ErrorHandler { export class ErrorHandler {
@ -46,9 +48,9 @@ export class ErrorHandler {
constructor(rethrowError: boolean = true) { this.rethrowError = rethrowError; } constructor(rethrowError: boolean = true) { this.rethrowError = rethrowError; }
handleError(error: any): void { handleError(error: any): void {
var originalError = this._findOriginalError(error); const originalError = this._findOriginalError(error);
var originalStack = this._findOriginalStack(error); const originalStack = this._findOriginalStack(error);
var context = this._findContext(error); const context = this._findContext(error);
this._console.error(`EXCEPTION: ${this._extractMessage(error)}`); this._console.error(`EXCEPTION: ${this._extractMessage(error)}`);
@ -81,14 +83,14 @@ export class ErrorHandler {
if (error) { if (error) {
return error.context ? error.context : return error.context ? error.context :
this._findContext((error as WrappedError).originalError); this._findContext((error as WrappedError).originalError);
} else {
return null;
} }
return null;
} }
/** @internal */ /** @internal */
_findOriginalError(error: any): any { _findOriginalError(error: any): any {
var e = (error as WrappedError).originalError; let e = (error as WrappedError).originalError;
while (e && (e as WrappedError).originalError) { while (e && (e as WrappedError).originalError) {
e = (e as WrappedError).originalError; e = (e as WrappedError).originalError;
} }
@ -100,8 +102,8 @@ export class ErrorHandler {
_findOriginalStack(error: any): string { _findOriginalStack(error: any): string {
if (!(error instanceof Error)) return null; if (!(error instanceof Error)) return null;
var e: any = error; let e: any = error;
var stack: string = e.stack; let stack: string = e.stack;
while (e instanceof Error && (e as WrappedError).originalError) { while (e instanceof Error && (e as WrappedError).originalError) {
e = (e as WrappedError).originalError; e = (e as WrappedError).originalError;
if (e instanceof Error && e.stack) { if (e instanceof Error && e.stack) {