microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
src/common/error/InternalError.ts
39lines · 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 | |
| 28 | constructor(errorCode: number, message: string, innerError: any) { |
| 29 | super(errorCode, message); |
| 30 | this.innerError = innerError; |
| 31 | this.name = innerError ? innerError.name : null; |
| 32 | const innerMessage = innerError ? innerError.message : null; |
| 33 | this.message = innerMessage ? `${message}: ${innerMessage}` : message; |
| 34 | } |
| 35 | |
| 36 | public static getWrappedError(error: InternalError, innerError: any): NestedError { |
| 37 | return new NestedError(error.errorCode, error.message, innerError); |
| 38 | } |
| 39 | } |