better error management

This commit is contained in:
Kasra Bigdeli
2019-01-06 16:40:47 -08:00
parent 5d6e6c3e9b
commit 58273efcb2
3 changed files with 52 additions and 7 deletions
+20 -3
View File
@@ -21,6 +21,7 @@ const ErrorFactory_1 = require("../utils/ErrorFactory");
const SpinnerHelper_1 = require("../utils/SpinnerHelper");
let newPasswordFirstTry = undefined;
let lastWorkingPassword = Constants_1.default.DEFAULT_PASSWORD;
let serverIpAddress = '';
let captainMachine = {
authToken: '',
baseUrl: '',
@@ -56,6 +57,7 @@ const questions = [
// login using captain42. and set the ipAddressToServer
captainMachine.baseUrl = `http://${ipFromUser}:3000`;
yield CliApiManager_1.default.get(captainMachine).getAuthToken(lastWorkingPassword);
serverIpAddress = ipFromUser;
}
catch (e) {
// User may have used a different default password
@@ -86,8 +88,7 @@ const questions = [
type: 'input',
name: 'captainRootDomain',
message: 'Enter a root domain for this Captain server. For example, enter test.yourdomain.com if you' +
' setup your DNS to point *.test.yourdomain.com to ip address of your server' +
': ',
' setup your DNS to point *.test.yourdomain.com to ip address of your server.',
filter: (value) => __awaiter(this, void 0, void 0, function* () {
const captainRootDomainFromUser = value.trim();
try {
@@ -96,6 +97,18 @@ const questions = [
captainMachine.baseUrl = `http://captain.${captainRootDomainFromUser}`;
}
catch (e) {
StdOutUtil_1.default.printError('\n\n');
if (e.captainStatus === ErrorFactory_1.default.VERIFICATION_FAILED) {
if (captainRootDomainFromUser.indexOf('/') >= 0) {
StdOutUtil_1.default.printError('DO NOT include http in your base domain, it should be just plain domain, e.g., test.domain.com');
}
if (captainRootDomainFromUser.indexOf('*') >= 0) {
StdOutUtil_1.default.printError('DO NOT include * in your base domain, it should be just plain domain, e.g., test.domain.com');
}
StdOutUtil_1.default.printError(`\n\nCannot verify that http://captain.${captainRootDomainFromUser} points to your server IP.\n` +
`\nAre you sure that you set *.${captainRootDomainFromUser} points to ${serverIpAddress}\n\n` +
`Double check your DNS. If everything looks correct, note that, DNS changes take up to 24 hrs to work properly. Check with your Domain Provider.`);
}
StdOutUtil_1.default.errorHandler(e);
}
return captainRootDomainFromUser;
@@ -107,6 +120,10 @@ const questions = [
message: 'Enter a new password:',
filter: (value) => {
newPasswordFirstTry = value;
if (!newPasswordFirstTry) {
StdOutUtil_1.default.printError('Password empty.', true);
throw new Error('Password empty');
}
return value;
}
},
@@ -116,7 +133,7 @@ const questions = [
message: 'Enter your new password again:',
filter: (value) => __awaiter(this, void 0, void 0, function* () {
const confirmPasswordValueFromUser = value;
if (newPasswordFirstTry !== confirmPasswordValueFromUser) {
if ((newPasswordFirstTry !== confirmPasswordValueFromUser)) {
StdOutUtil_1.default.printError('Passwords do not match. Try serversetup again.', true);
throw new Error('Password mismatch');
}
File diff suppressed because one or more lines are too long
+31 -3
View File
@@ -14,6 +14,7 @@ import SpinnerHelper from '../utils/SpinnerHelper';
let newPasswordFirstTry: string | undefined = undefined;
let lastWorkingPassword: string = Constants.DEFAULT_PASSWORD;
let serverIpAddress = '';
let captainMachine: IMachine = {
authToken: '',
@@ -58,6 +59,7 @@ const questions = [
// login using captain42. and set the ipAddressToServer
captainMachine.baseUrl = `http://${ipFromUser}:3000`;
await CliApiManager.get(captainMachine).getAuthToken(lastWorkingPassword);
serverIpAddress = ipFromUser;
} catch (e) {
// User may have used a different default password
if (e.captainStatus === ErrorFactory.STATUS_WRONG_PASSWORD) return '';
@@ -87,8 +89,7 @@ const questions = [
name: 'captainRootDomain',
message:
'Enter a root domain for this Captain server. For example, enter test.yourdomain.com if you' +
' setup your DNS to point *.test.yourdomain.com to ip address of your server' +
': ',
' setup your DNS to point *.test.yourdomain.com to ip address of your server.',
filter: async (value: string) => {
const captainRootDomainFromUser = value.trim();
try {
@@ -96,6 +97,26 @@ const questions = [
captainMachine = Utils.copyObject(captainMachine);
captainMachine.baseUrl = `http://captain.${captainRootDomainFromUser}`;
} catch (e) {
StdOutUtil.printError('\n\n');
if (e.captainStatus === ErrorFactory.VERIFICATION_FAILED) {
if (captainRootDomainFromUser.indexOf('/') >= 0) {
StdOutUtil.printError(
'DO NOT include http in your base domain, it should be just plain domain, e.g., test.domain.com'
);
}
if (captainRootDomainFromUser.indexOf('*') >= 0) {
StdOutUtil.printError(
'DO NOT include * in your base domain, it should be just plain domain, e.g., test.domain.com'
);
}
StdOutUtil.printError(
`\n\nCannot verify that http://captain.${captainRootDomainFromUser} points to your server IP.\n` +
`\nAre you sure that you set *.${captainRootDomainFromUser} points to ${serverIpAddress}\n\n` +
`Double check your DNS. If everything looks correct, note that, DNS changes take up to 24 hrs to work properly. Check with your Domain Provider.`
);
}
StdOutUtil.errorHandler(e);
}
@@ -108,6 +129,12 @@ const questions = [
message: 'Enter a new password:',
filter: (value: string) => {
newPasswordFirstTry = value;
if (!newPasswordFirstTry) {
StdOutUtil.printError('Password empty.', true);
throw new Error('Password empty');
}
return value;
}
},
@@ -118,10 +145,11 @@ const questions = [
filter: async (value: string) => {
const confirmPasswordValueFromUser = value;
if (newPasswordFirstTry !== confirmPasswordValueFromUser) {
if ((newPasswordFirstTry !== confirmPasswordValueFromUser)) {
StdOutUtil.printError('Passwords do not match. Try serversetup again.', true);
throw new Error('Password mismatch');
}
return '';
}
},