diff --git a/src/bin/vip-app.js b/src/bin/vip-app.js index 65d5e7e49..291464d34 100755 --- a/src/bin/vip-app.js +++ b/src/bin/vip-app.js @@ -5,6 +5,7 @@ import chalk from 'chalk'; import app from '../lib/api/app'; import command, { getEnvIdentifier } from '../lib/cli/command'; import { trackEvent } from '../lib/tracker'; +import { parseApiError } from '../lib/utils'; command( { requiredArgs: 1, format: true } ) .example( @@ -41,7 +42,17 @@ command( { requiredArgs: 1, format: true } ) error: `App ${ arg[ 0 ] } does not exist`, } ); - console.log( `App ${ chalk.blueBright( arg[ 0 ] ) } does not exist` ); + const apiErrorMsg = parseApiError( err ); + + let errorMsg = `Unable to locate app ${ chalk.blueBright( arg[ 0 ] ) }`; + + if ( apiErrorMsg ) { + errorMsg += ': ' + apiErrorMsg; + } else { + errorMsg += ': Invalid application or connection issue?'; + } + + console.log( errorMsg ); return; } @@ -50,7 +61,7 @@ command( { requiredArgs: 1, format: true } ) error: `App ${ arg[ 0 ] } does not exist`, } ); - console.log( `App ${ chalk.blueBright( arg[ 0 ] ) } does not exist` ); + console.log( `App ${ chalk.blueBright( arg[ 0 ] ) } was not found` ); return; } diff --git a/src/lib/cli/command.js b/src/lib/cli/command.js index 875911ab1..d07770950 100644 --- a/src/lib/cli/command.js +++ b/src/lib/cli/command.js @@ -12,6 +12,7 @@ import pkg from '../../../package.json'; import API from '../../lib/api'; import app from '../../lib/api/app'; import { trackEvent } from '../../lib/tracker'; +import { parseApiError } from '../../lib/utils'; import UserError from '../user-error'; function uncaughtError( err ) { @@ -232,7 +233,7 @@ args.argv = async function ( argv, cb ) { error: 'Invalid app selected', } ); - exit.withError( `App ${ chalk.blueBright( appSelection.app.name ) } does not exist` ); + exit.withError( `App ${ chalk.blueBright( appSelection.app.name ) } could not be located` ); } await trackEvent( 'command_appcontext_list_select_success' ); @@ -247,7 +248,17 @@ args.argv = async function ( argv, cb ) { error: 'App lookup failed', } ); - exit.withError( `App ${ chalk.blueBright( options.app ) } does not exist` ); + const apiErrorMsg = parseApiError( err ); + + let errorMsg = `Unable to find app ${ chalk.blueBright( options.app ) }`; + + if ( apiErrorMsg ) { + errorMsg += ': ' + apiErrorMsg; + } else { + errorMsg += ': Invalid application or connection issue?'; + } + + exit.withError( errorMsg ); } if ( ! appLookup?.id ) { diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 66c5661c2..d199ee3a0 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -75,3 +75,31 @@ export function getAbsolutePath( filePath: string ): string { return filePath; } + +/** + * Parse error object and return probable error. + * + * @param {Error} Error object + * + * @return {string|null} Error string when error was found, otherwise null. + */ + +export function parseApiError( err: { + networkError?: { message?: string }; + message?: string; + graphQLErrors: unknown[]; +} ): string | null { + if ( err?.networkError?.message ) { + return err?.networkError?.message; + } + + if ( err?.graphQLErrors && err?.graphQLErrors?.length > 0 && err?.graphQLErrors[ 0 ]?.message ) { + return err?.graphQLErrors[ 0 ]?.message; + } + + if ( err?.message ) { + return err?.message; + } + + return null; +}