Skip to content

Commit

Permalink
Lint files from lib/common directory.
Browse files Browse the repository at this point in the history
issue #71
  • Loading branch information
tzmanics committed Feb 18, 2016
1 parent fa8b0b8 commit ffdaa0d
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 195 deletions.
32 changes: 19 additions & 13 deletions lib/common/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,32 @@
*
*/

var UserConfig = require('./userConfig'),
url = require('url'),
librarian = require('../librarian/librarian'),
userConfig = new UserConfig();
const URL = require('url');

userConfig.load();
const UserConfig = require('./userConfig');
const Librarian = require('../librarian/librarian');

if (userConfig.data && userConfig.data.api_uri) {
var url = url.parse(userConfig.data.api_uri);
const NewUserConfig = new UserConfig();
const HTTPS_PORT = 443;
const PORT = 80;

if (url.protocol === 'https:') {
librarian.init(url.hostname, url.port || 443, true);
var apiUri;

NewUserConfig.load();

if (NewUserConfig.data && NewUserConfig.data.api_uri) {
apiUri = URL.parse(NewUserConfig.data.api_uri);

if (apiUri.protocol === 'https:') {
Librarian.init(apiUri.hostname, apiUri.port || HTTPS_PORT, true);
} else {
librarian.init(url.hostname, url.port || 80, false);
Librarian.init(apiUri.hostname, apiUri.port || PORT, false);
}
} else {
librarian.init('api.onmodulus.net', 443, true);
Librarian.init('api.onmodulus.net', HTTPS_PORT, true);
}

module.exports = {
librarian : librarian,
userConfig : new UserConfig()
librarian: Librarian,
userConfig: new UserConfig()
};
4 changes: 2 additions & 2 deletions lib/common/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
/*
* Log output color setup
*/
var colors = require('colors');
const Colors = require('colors');

colors.setTheme({
Colors.setTheme({
main: 'white',
silly: 'rainbow',
input: 'grey',
Expand Down
188 changes: 94 additions & 94 deletions lib/common/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,140 +21,140 @@
*
*/

var error = module.exports;
const Modulus = require('../modulus');

error.handlePromptError = function(err, cb) {
const Errors = module.exports;

Errors.handlePromptError = function (err, cb) {
// Check if canceled by the user (CTRL+C)
if (err.message && err.message === 'canceled') {
console.log(''); //Extra space.
Modulus.io.print(); // Extra space.
return cb('Canceled by user.');
}

return cb(err);
};

error.handleApiError = function(err, command, cb) {
var e = error.getError(err, command);
Errors.handleApiError = function (err, command, cb) {
var e = Errors.getError(err, command);

if(e.level < 2) {
if (e.level < 2) {
cb(e.message);
return '';
} else {
return e.message;
}

return e.message;
};

error.getError = function(err, command) {
Errors.getError = function (err, command) {
var error, code, ret;
var id = 'DEFAULT';
var msg = '';

if (err.code) {
id = err.code;
} else if(err.errors && err.errors.length > 0) {
if (err.code) id = err.code;
if (err.errors && err.errors.length > 0) {
id = err.errors[0].id;
msg = err.errors[0].message;
}

for (var e in error.responseCodes) {
if (id === e) {
for (error in Errors.responseCodes) {
if (id === error) {
// If there is no message set,
// use the message from congress
if (!error.responseCodes[e].message) {
var ret = error.responseCodes[e];
if (!Errors.responseCodes[error].message) {
ret = Errors.responseCodes[error];
ret.message = msg;

return ret;
}

return error.responseCodes[e];
return Errors.responseCodes[error];
}
}

if (typeof command === 'string') {
for (var c in error.commandCodes) {
if (command === c) {
return error.commandCodes[c];
}
for (code in Errors.commandCodes) {
if (command === code) return Errors.commandCodes[code];
}
}

return error.responseCodes.DEFAULT;
return Errors.responseCodes.DEFAULT;
};

/*--- Error Codes ---*/
/* --- Error Codes --- */
// Level 0 - Something very bad happened, panic.
// Level 1 - Processing error, do not continue.
// Level 2 - Format/Input error, try again.
error.responseCodes = {
DEFAULT : {
id : 'DEFAULT',
level : 1,
message : 'There was an error processing your request.'
},
ECONNREFUSED : {
id : 'ECONNREFUSED',
level : 1,
message : 'Could not connect to Modulus.'
},
INVALID_AUTH : {
id : 'INVALID_AUTH',
level : 1,
message : 'Your session has expired. Please log in to continue.'
},
USERNAME_ALREADY_EXISTS : {
id : 'USERNAME_ALREADY_EXISTS',
level : 2,
message : null
},
EMAIL_ALREADY_EXISTS : {
id : 'EMAIL_ALREADY_EXISTS',
level : 2,
message : null
},
BETA_KEY_NOT_FOUND : {
id : 'BETA_KEY_NOT_FOUND',
level : 2,
message : null
},
BETA_KEY_ALEADY_USED : {
id : 'BETA_KEY_ALEADY_USED',
level : 2,
message : null
},
PROJECT_LIMIT_REACHED : {
id : 'PROJECT_LIMIT_REACHED',
level : 1,
message : null
},
NO_CAPACITY : {
id : 'NO_CAPACITY',
level : 2,
message : 'Not enough capacity for new project. New capacity is being added now. Please attempt the request again in a few minutes.'
Errors.responseCodes = {
DEFAULT: {
id: 'DEFAULT',
level: 1,
message: 'There was an error processing your request.'
},
ECONNREFUSED: {
id: 'ECONNREFUSED',
level: 1,
message: 'Could not connect to Modulus.'
},
INVALID_AUTH: {
id: 'INVALID_AUTH',
level: 1,
message: 'Your session has expired. Please log in to continue.'
},
USERNAME_ALREADY_EXISTS: {
id: 'USERNAME_ALREADY_EXISTS',
level: 2,
message: null
},
EMAIL_ALREADY_EXISTS: {
id: 'EMAIL_ALREADY_EXISTS',
level: 2,
message: null
},
BETA_KEY_NOT_FOUND: {
id: 'BETA_KEY_NOT_FOUND',
level: 2,
message: null
},
BETA_KEY_ALEADY_USED: {
id: 'BETA_KEY_ALEADY_USED',
level: 2,
message: null
},
PROJECT_LIMIT_REACHED: {
id: 'PROJECT_LIMIT_REACHED',
level: 1,
message: null
},
NO_CAPACITY: {
id: 'NO_CAPACITY',
level: 2,
message: 'Not enough capacity for new project. New capacity is being added now. Please attempt the request again in a few minutes.'
},
PROJECT_ZIP_TOO_LARGE: {
id : 'PROJECT_ZIP_TOO_LARGE',
level : 1,
message : 'Your application must be less than 1gb in size.'
id: 'PROJECT_ZIP_TOO_LARGE',
level: 1,
message: 'Your application must be less than 1gb in size.'
},
NO_MATCHING_NAME: {
id : 'NO_MATCHING_NAME',
id: 'NO_MATCHING_NAME',
level: 1,
message: 'No project found that matches specified name.'
},
NO_MATCHING_DB_NAME: {
id : 'NO_MATCHING_DB_NAME',
id: 'NO_MATCHING_DB_NAME',
level: 1,
message: 'No database found that matches specified name.'
},
OAUTH_TOKEN_NOT_FOUND: {
id : 'OAUTH_TOKEN_NOT_FOUND',
level : 1,
message : 'Please link your account with GitHub using the web portal to use GitHub authentication.'
id: 'OAUTH_TOKEN_NOT_FOUND',
level: 1,
message: 'Please link your account with GitHub using the web portal to use GitHub authentication.'
},
SINGLE_SIGN_ON_USER_NOT_FOUND: {
id : 'SINGLE_SIGN_ON_USER_NOT_FOUND',
level : 1,
message : 'GitHub account not found. Please link your account with GitHub using the web portal to use GitHub authentication.'
id: 'SINGLE_SIGN_ON_USER_NOT_FOUND',
level: 1,
message: 'GitHub account not found. Please link your account with GitHub using the web portal to use GitHub authentication.'
},
INVALID_ENV_VARIABLE_VALUE: {
id: 'INVALID_ENV_VARIABLE_VALUE',
Expand Down Expand Up @@ -228,20 +228,20 @@ error.responseCodes = {
}
};

error.commandCodes = {
LOGIN : {
id : 'LOGIN',
level : 2,
message : 'Username or Password incorrect.\nFor Github users, use the --github option.'
},
CREATE_MONGO : {
id : 'CREATE_MONGO',
level : 1,
message : 'MongoDB database could not be created.'
},
GET_DATABASES : {
id : 'GET_DATABASES',
level : 1,
message : 'Could not retreive databases for user.'
Errors.commandCodes = {
LOGIN: {
id: 'LOGIN',
level: 2,
message: 'Username or Password incorrect.\nFor Github users, use the --github option.'
},
CREATE_MONGO: {
id: 'CREATE_MONGO',
level: 1,
message: 'MongoDB database could not be created.'
},
GET_DATABASES: {
id: 'GET_DATABASES',
level: 1,
message: 'Could not retreive databases for user.'
}
};
Loading

0 comments on commit ffdaa0d

Please sign in to comment.