Skip to content

Commit

Permalink
move api_deprecated code, change array to obj in response
Browse files Browse the repository at this point in the history
  • Loading branch information
nagpalkaran95 committed May 7, 2020
1 parent 148f056 commit c1caee0
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 48 deletions.
36 changes: 21 additions & 15 deletions bin/commands/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,9 @@ function buildInfo(args) {
build = null;
}

if (resp.statusCode != 200) {
messageType = Constants.messageTypes.ERROR;
errorCode = 'api_failed_build_info';

if (build) {
message = `${Constants.userMessages.BUILD_INFO_FAILED} with error: \n${JSON.stringify(build, null, 2)}`;
logger.error(message);
if (build.message === 'Unauthorized') errorCode = 'api_auth_failed';
} else {
message = Constants.userMessages.BUILD_INFO_FAILED;
logger.error(message);
}
} else if (resp.statusCode == 299) {
if (resp.statusCode == 299) {
messageType = Constants.messageTypes.INFO;
errorCode = 'api_deprecated';
errorCode = "api_deprecated";

if (build) {
message = build.message;
Expand All @@ -69,9 +57,27 @@ function buildInfo(args) {
message = Constants.userMessages.API_DEPRECATED;
logger.info(message);
}
} else if (resp.statusCode != 200) {
messageType = Constants.messageTypes.ERROR;
errorCode = "api_failed_build_info";

if (build) {
message = `${
Constants.userMessages.BUILD_INFO_FAILED
} with error: \n${JSON.stringify(build, null, 2)}`;
logger.error(message);
if (build.message === "Unauthorized") errorCode = "api_auth_failed";
} else {
message = Constants.userMessages.BUILD_INFO_FAILED;
logger.error(message);
}
} else {
messageType = Constants.messageTypes.SUCCESS;
message = `Build info for build id: \n ${JSON.stringify(build, null, 2)}`;
message = `Build info for build id: \n ${JSON.stringify(
build,
null,
2
)}`;
logger.info(message);
}
}
Expand Down
32 changes: 17 additions & 15 deletions bin/commands/stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,31 @@ function buildStop(args) {
build = null
}

if (resp.statusCode != 200) {
messageType = Constants.messageTypes.ERROR;
errorCode = 'api_failed_build_stop';

if (build) {
message = `${Constants.userMessages.BUILD_STOP_FAILED} with error: \n${JSON.stringify(build, null, 2)}`;
logger.error(message);
if (build.message === 'Unauthorized') errorCode = 'api_auth_failed';
} else {
message = Constants.userMessages.BUILD_STOP_FAILED;
logger.error(message);
}
} else if (resp.statusCode == 299) {
if (resp.statusCode == 299) {
messageType = Constants.messageTypes.INFO;
errorCode = 'api_deprecated';
errorCode = "api_deprecated";

if (build) {
message = build.message
message = build.message;
logger.info(message);
} else {
message = Constants.userMessages.API_DEPRECATED;
logger.info(message);
}
} else if (resp.statusCode != 200) {
messageType = Constants.messageTypes.ERROR;
errorCode = "api_failed_build_stop";

if (build) {
message = `${
Constants.userMessages.BUILD_STOP_FAILED
} with error: \n${JSON.stringify(build, null, 2)}`;
logger.error(message);
if (build.message === "Unauthorized") errorCode = "api_auth_failed";
} else {
message = Constants.userMessages.BUILD_STOP_FAILED;
logger.error(message);
}
} else {
messageType = Constants.messageTypes.SUCCESS;
message = `${JSON.stringify(build, null, 2)}`;
Expand Down
23 changes: 14 additions & 9 deletions bin/helpers/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,26 @@ const createBuild = (bsConfig, zip) => {
} catch (error) {
build = null
}
if (resp.statusCode != 201) {

if (resp.statusCode == 299) {
if (build) {
logger.error(`${Constants.userMessages.BUILD_FAILED} Error: ${build.message}`);
} else {
logger.error(Constants.userMessages.BUILD_FAILED);
}
} else if(resp.statusCode == 299){
if(build) {
logger.info(build.message);
} else {
logger.info(Constants.userMessages.API_DEPRECATED);
}
} else if (resp.statusCode != 201) {
if (build) {
logger.error(
`${Constants.userMessages.BUILD_FAILED} Error: ${build.message}`
);
} else {
logger.error(Constants.userMessages.BUILD_FAILED);
}
} else {
logger.info(build.message)
logger.info(`${Constants.userMessages.BUILD_CREATED} with build id: ${build.build_id}`);
logger.info(build.message);
logger.info(
`${Constants.userMessages.BUILD_CREATED} with build id: ${build.build_id}`
);
}
resolve(build);
}
Expand Down
32 changes: 23 additions & 9 deletions bin/helpers/usageReporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,34 @@ function cli_version_and_path(bsConfig) {

if (!version) {
// return path = null if version is null
return [null, null];
return {
version: null,
path: null
};
}
_path = npm_global_path();
return [version, _path];
return {
version: version,
path: npm_global_path(),
};
}
return [version, _path];
return {
version: version,
path: _path,
};
} else {
let version = get_version('browserstack-cypress');

if (!version) {
// return path = null if version is null
return [null, null];
return {
version: null,
path: null,
};
}
return [version, npm_global_path()];
return {
version: version,
path: npm_global_path(),
};
}
}

Expand Down Expand Up @@ -159,7 +173,7 @@ function send(args) {
if (!isUsageReportingEnabled()) return;

let bsConfig = args.bstack_config;
let [cli_version, cli_path] = cli_version_and_path(bsConfig);
let cli_details = cli_version_and_path(bsConfig);

delete args.bstack_config;

Expand All @@ -170,8 +184,8 @@ function send(args) {
os_version: os_version(),
bstack_json_found_in_pwd: bstack_json_found_in_pwd(),
cypress_json_found_in_pwd: cypress_json_found_in_pwd(),
cli_version: cli_version,
cli_path: cli_path,
cli_version: cli_details.version,
cli_path: cli_details.path,
npm_version: npm_version(),
local_cypress_version: local_cypress_version(bsConfig),
ci_environment: ci_environment(),
Expand Down

0 comments on commit c1caee0

Please sign in to comment.