Skip to content

Commit 6af9c6e

Browse files
author
Tim Mendoza
committed
Add new error for missing API key. Improve existing errors
1 parent 0a71af0 commit 6af9c6e

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/helpers.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const { APP_NAME, EXPIRY_PERIOD } = require('./constants');
22
const { cli } = require('cli-ux');
3+
const { CLIError } = require('@oclif/errors');
34
const fs = require('fs');
45
const { getListOfFunctionsAndAssets } = require('@twilio-labs/serverless-api/dist/utils/fs');
56
const 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() {
112113
async 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

Comments
 (0)