mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-21 14:02:43 +08:00
Errors thrown in RxJs are not instanceof Error and therefore the check will always fail. Closes #23631
18 lines
596 B
TypeScript
18 lines
596 B
TypeScript
/**
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
|
|
import assert from 'assert';
|
|
|
|
export function assertIsError(value: unknown): asserts value is Error & { code?: string } {
|
|
const isError =
|
|
value instanceof Error ||
|
|
// The following is needing to identify errors coming from RxJs.
|
|
(typeof value === 'object' && value && 'name' in value && 'message' in value);
|
|
assert(isError, 'catch clause variable is not an Error instance');
|
|
}
|