microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/appcenter/command/commandResult.ts
48lines · modeblame
bb45fbe6max-mironov8 years ago | 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 type CommandResult = CommandSucceededResult | CommandFailedResult; | |
| 5 | | |
| 6 | export interface CommandSucceededResult { | |
| 7 | succeeded: boolean; | |
86466695max-mironov8 years ago | 8 | result?: any; |
bb45fbe6max-mironov8 years ago | 9 | } |
| 10 | | |
| 11 | export interface CommandFailedResult { | |
| 12 | succeeded: boolean; | |
| 13 | errorCode: number; | |
| 14 | errorMessage: string; | |
| 15 | exception?: Error; | |
| 16 | } | |
86466695max-mironov8 years ago | 17 | |
| 18 | export function success(res: any): CommandResult { | |
| 19 | return { | |
| 20 | succeeded: true, | |
| 21 | result: res, | |
| 22 | }; | |
| 23 | } | |
| 24 | | |
| 25 | // Used when there's a failure otherwise | |
| 26 | export function failure(errorCode: number, errorMessage: string): CommandResult { | |
| 27 | return { | |
| 28 | succeeded: false, | |
| 29 | errorCode, | |
| 30 | errorMessage, | |
| 31 | }; | |
| 32 | } | |
| 33 | | |
| 34 | export enum ErrorCodes { | |
| 35 | Succeeded = 0, | |
| 36 | // Command given contained illegal characters/names | |
| 37 | IllegalCommand, | |
| 38 | // Command was legal, but not found | |
| 39 | NoSuchCommand, | |
| 40 | // Unhandled exception occurred | |
| 41 | Exception, | |
| 42 | // A parameter is invalid | |
| 43 | InvalidParameter, | |
| 44 | // Command requires logged in user | |
| 45 | NotLoggedIn, | |
| 46 | // The requested resource was not found | |
| 47 | NotFound, | |
| 48 | } |