microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
src/common/error/internalError.ts
45lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for details. |
| 3 | |
| 4 | export enum InternalErrorLevel { |
| 5 | Error, |
| 6 | Warning |
| 7 | } |
| 8 | |
| 9 | export class InternalError extends Error { |
| 10 | public errorCode: number; |
| 11 | public errorLevel: InternalErrorLevel; |
| 12 | |
| 13 | public get isInternalError(): boolean { |
| 14 | return true; |
| 15 | } |
| 16 | |
| 17 | constructor(errorCode: number, message: string, errorLevel: InternalErrorLevel = InternalErrorLevel.Error) { |
| 18 | super(message); |
| 19 | this.errorCode = errorCode; |
| 20 | this.errorLevel = errorLevel; |
| 21 | this.message = message; |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | export class NestedError extends InternalError { |
| 26 | public innerError: Error | any; // Normally this should be an error, but we support any value |
| 27 | private _extras: any; |
| 28 | |
| 29 | constructor(errorCode: number, message: string, innerError: any = null, extras?: any, errorLevel: InternalErrorLevel = InternalErrorLevel.Error) { |
| 30 | super(errorCode, message, errorLevel); |
| 31 | this.innerError = innerError; |
| 32 | this.name = innerError ? innerError.name : null; |
| 33 | const innerMessage = innerError ? innerError.message : null; |
| 34 | this.message = innerMessage ? `${message}: ${innerMessage}` : message; |
| 35 | this._extras = extras; |
| 36 | } |
| 37 | |
| 38 | public get extras(): any { |
| 39 | return this._extras; |
| 40 | } |
| 41 | |
| 42 | public static getWrappedError(error: InternalError, innerError: any): NestedError { |
| 43 | return new NestedError(innerError.errorCode || error.errorCode, error.message, innerError); |
| 44 | } |
| 45 | } |