microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
fix-ts-error1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/common/error/internalError.ts

55lines · modeblame

17161993Meena Kunnathur Balakrishnan10 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
190e393cMeena Kunnathur Balakrishnan10 years ago4export enum InternalErrorLevel {
5Error,
27710197Vladimir Kotikov8 years ago6Warning,
190e393cMeena Kunnathur Balakrishnan10 years ago7}
8
17161993Meena Kunnathur Balakrishnan10 years ago9export class InternalError extends Error {
10public errorCode: number;
190e393cMeena Kunnathur Balakrishnan10 years ago11public errorLevel: InternalErrorLevel;
12
13public get isInternalError(): boolean {
14return true;
15}
17161993Meena Kunnathur Balakrishnan10 years ago16
34472878RedMickey5 years ago17constructor(
18errorCode: number,
19message: string,
20errorLevel: InternalErrorLevel = InternalErrorLevel.Error,
21) {
17161993Meena Kunnathur Balakrishnan10 years ago22super(message);
23this.errorCode = errorCode;
190e393cMeena Kunnathur Balakrishnan10 years ago24this.errorLevel = errorLevel;
09f6024fHeniker4 years ago25this.message = errorCode > 0 ? `${message} (error code ${this.errorCode})` : message;
17161993Meena Kunnathur Balakrishnan10 years ago26}
27}
28
29export class NestedError extends InternalError {
30public innerError: Error | any; // Normally this should be an error, but we support any value
898cb3c6Meena Kunnathur Balakrishnan10 years ago31private _extras: any;
17161993Meena Kunnathur Balakrishnan10 years ago32
34472878RedMickey5 years ago33constructor(
34errorCode: number,
35message: string,
36innerError: any = null,
37extras?: any,
38errorLevel: InternalErrorLevel = InternalErrorLevel.Error,
39) {
a4a7e387Meena Kunnathur Balakrishnan10 years ago40super(errorCode, message, errorLevel);
17161993Meena Kunnathur Balakrishnan10 years ago41this.innerError = innerError;
42this.name = innerError ? innerError.name : null;
43const innerMessage = innerError ? innerError.message : null;
09f6024fHeniker4 years ago44this.message = innerMessage ? `${message}: ${String(innerMessage)}` : message;
898cb3c6Meena Kunnathur Balakrishnan10 years ago45this._extras = extras;
46}
47
48public get extras(): any {
49return this._extras;
17161993Meena Kunnathur Balakrishnan10 years ago50}
190e393cMeena Kunnathur Balakrishnan10 years ago51
52public static getWrappedError(error: InternalError, innerError: any): NestedError {
2166bdabdigeff10 years ago53return new NestedError(innerError.errorCode || error.errorCode, error.message, innerError);
190e393cMeena Kunnathur Balakrishnan10 years ago54}
27710197Vladimir Kotikov8 years ago55}