11const { APP_NAME , EXPIRY_PERIOD } = require ( './constants' ) ;
22const { cli } = require ( 'cli-ux' ) ;
3+ const { CLIError } = require ( '@oclif/errors' ) ;
34const fs = require ( 'fs' ) ;
45const { getListOfFunctionsAndAssets } = require ( '@twilio-labs/serverless-api/dist/utils/fs' ) ;
56const moment = require ( 'moment' ) ;
@@ -21,18 +22,18 @@ function verifyAppDirectory(dirpath) {
2122 const hasIndexHTML = [ ...dir ] . includes ( 'index.html' ) ;
2223
2324 if ( ! hasIndexHTML ) {
24- throw new Error (
25+ throw new CLIError (
2526 'The provided app-directory does not appear to be a valid app. There is no index.html found in the app-directory.'
2627 ) ;
2728 }
2829 } catch ( err ) {
2930 switch ( err . code ) {
3031 case 'ENOENT' :
31- throw new Error ( 'The provided app-directory does not exist.' ) ;
32+ throw new CLIError ( 'The provided app-directory does not exist.' ) ;
3233 case 'ENOTDIR' :
33- throw new Error ( 'The provided app-directory is not a directory.' ) ;
34+ throw new CLIError ( 'The provided app-directory is not a directory.' ) ;
3435 default :
35- throw new Error ( err . message ) ;
36+ throw new CLIError ( err . message ) ;
3637 }
3738 }
3839}
@@ -112,6 +113,25 @@ async function displayAppInfo() {
112113async function deploy ( ) {
113114 const assets = this . flags [ 'app-directory' ] ? await getAssets ( this . flags [ 'app-directory' ] ) : [ ] ;
114115
116+ if ( this . twilioClient . username === this . twilioClient . accountSid ) {
117+ // When twilioClient.username equals twilioClient.accountSid, it means that the user
118+ // authenticated with the Twilio CLI by providing their Account SID and Auth Token
119+ // as environment variables. When this happens, the CLI does not create the required API
120+ // key that is needed by the token server.
121+
122+ throw new CLIError ( `No API Key found.
123+
124+ Please login to the Twilio CLI to create an API key:
125+
126+ twilio login
127+
128+ Alternatively, the Twilio CLI can use credentials stored in these environment variables:
129+
130+ TWILIO_ACCOUNT_SID = your Account SID from twil.io/console
131+ TWILIO_API_KEY = an API Key created at twil.io/get-api-key
132+ TWILIO_API_SECRET = the secret for the API Key` ) ;
133+ }
134+
115135 const serverlessClient = new TwilioServerlessApiClient ( {
116136 accountSid : this . twilioClient . username ,
117137 authToken : this . twilioClient . password ,
0 commit comments