Skip to content

Commit c1caee0

Browse files
committed
move api_deprecated code, change array to obj in response
1 parent 148f056 commit c1caee0

File tree

4 files changed

+75
-48
lines changed

4 files changed

+75
-48
lines changed

bin/commands/info.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,9 @@ function buildInfo(args) {
4646
build = null;
4747
}
4848

49-
if (resp.statusCode != 200) {
50-
messageType = Constants.messageTypes.ERROR;
51-
errorCode = 'api_failed_build_info';
52-
53-
if (build) {
54-
message = `${Constants.userMessages.BUILD_INFO_FAILED} with error: \n${JSON.stringify(build, null, 2)}`;
55-
logger.error(message);
56-
if (build.message === 'Unauthorized') errorCode = 'api_auth_failed';
57-
} else {
58-
message = Constants.userMessages.BUILD_INFO_FAILED;
59-
logger.error(message);
60-
}
61-
} else if (resp.statusCode == 299) {
49+
if (resp.statusCode == 299) {
6250
messageType = Constants.messageTypes.INFO;
63-
errorCode = 'api_deprecated';
51+
errorCode = "api_deprecated";
6452

6553
if (build) {
6654
message = build.message;
@@ -69,9 +57,27 @@ function buildInfo(args) {
6957
message = Constants.userMessages.API_DEPRECATED;
7058
logger.info(message);
7159
}
60+
} else if (resp.statusCode != 200) {
61+
messageType = Constants.messageTypes.ERROR;
62+
errorCode = "api_failed_build_info";
63+
64+
if (build) {
65+
message = `${
66+
Constants.userMessages.BUILD_INFO_FAILED
67+
} with error: \n${JSON.stringify(build, null, 2)}`;
68+
logger.error(message);
69+
if (build.message === "Unauthorized") errorCode = "api_auth_failed";
70+
} else {
71+
message = Constants.userMessages.BUILD_INFO_FAILED;
72+
logger.error(message);
73+
}
7274
} else {
7375
messageType = Constants.messageTypes.SUCCESS;
74-
message = `Build info for build id: \n ${JSON.stringify(build, null, 2)}`;
76+
message = `Build info for build id: \n ${JSON.stringify(
77+
build,
78+
null,
79+
2
80+
)}`;
7581
logger.info(message);
7682
}
7783
}

bin/commands/stop.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,31 @@ function buildStop(args) {
4646
build = null
4747
}
4848

49-
if (resp.statusCode != 200) {
50-
messageType = Constants.messageTypes.ERROR;
51-
errorCode = 'api_failed_build_stop';
52-
53-
if (build) {
54-
message = `${Constants.userMessages.BUILD_STOP_FAILED} with error: \n${JSON.stringify(build, null, 2)}`;
55-
logger.error(message);
56-
if (build.message === 'Unauthorized') errorCode = 'api_auth_failed';
57-
} else {
58-
message = Constants.userMessages.BUILD_STOP_FAILED;
59-
logger.error(message);
60-
}
61-
} else if (resp.statusCode == 299) {
49+
if (resp.statusCode == 299) {
6250
messageType = Constants.messageTypes.INFO;
63-
errorCode = 'api_deprecated';
51+
errorCode = "api_deprecated";
6452

6553
if (build) {
66-
message = build.message
54+
message = build.message;
6755
logger.info(message);
6856
} else {
6957
message = Constants.userMessages.API_DEPRECATED;
7058
logger.info(message);
7159
}
60+
} else if (resp.statusCode != 200) {
61+
messageType = Constants.messageTypes.ERROR;
62+
errorCode = "api_failed_build_stop";
63+
64+
if (build) {
65+
message = `${
66+
Constants.userMessages.BUILD_STOP_FAILED
67+
} with error: \n${JSON.stringify(build, null, 2)}`;
68+
logger.error(message);
69+
if (build.message === "Unauthorized") errorCode = "api_auth_failed";
70+
} else {
71+
message = Constants.userMessages.BUILD_STOP_FAILED;
72+
logger.error(message);
73+
}
7274
} else {
7375
messageType = Constants.messageTypes.SUCCESS;
7476
message = `${JSON.stringify(build, null, 2)}`;

bin/helpers/build.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,26 @@ const createBuild = (bsConfig, zip) => {
3131
} catch (error) {
3232
build = null
3333
}
34-
if (resp.statusCode != 201) {
34+
35+
if (resp.statusCode == 299) {
3536
if (build) {
36-
logger.error(`${Constants.userMessages.BUILD_FAILED} Error: ${build.message}`);
37-
} else {
38-
logger.error(Constants.userMessages.BUILD_FAILED);
39-
}
40-
} else if(resp.statusCode == 299){
41-
if(build) {
4237
logger.info(build.message);
4338
} else {
4439
logger.info(Constants.userMessages.API_DEPRECATED);
4540
}
41+
} else if (resp.statusCode != 201) {
42+
if (build) {
43+
logger.error(
44+
`${Constants.userMessages.BUILD_FAILED} Error: ${build.message}`
45+
);
46+
} else {
47+
logger.error(Constants.userMessages.BUILD_FAILED);
48+
}
4649
} else {
47-
logger.info(build.message)
48-
logger.info(`${Constants.userMessages.BUILD_CREATED} with build id: ${build.build_id}`);
50+
logger.info(build.message);
51+
logger.info(
52+
`${Constants.userMessages.BUILD_CREATED} with build id: ${build.build_id}`
53+
);
4954
}
5055
resolve(build);
5156
}

bin/helpers/usageReporting.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,34 @@ function cli_version_and_path(bsConfig) {
8888

8989
if (!version) {
9090
// return path = null if version is null
91-
return [null, null];
91+
return {
92+
version: null,
93+
path: null
94+
};
9295
}
93-
_path = npm_global_path();
94-
return [version, _path];
96+
return {
97+
version: version,
98+
path: npm_global_path(),
99+
};
95100
}
96-
return [version, _path];
101+
return {
102+
version: version,
103+
path: _path,
104+
};
97105
} else {
98106
let version = get_version('browserstack-cypress');
99107

100108
if (!version) {
101109
// return path = null if version is null
102-
return [null, null];
110+
return {
111+
version: null,
112+
path: null,
113+
};
103114
}
104-
return [version, npm_global_path()];
115+
return {
116+
version: version,
117+
path: npm_global_path(),
118+
};
105119
}
106120
}
107121

@@ -159,7 +173,7 @@ function send(args) {
159173
if (!isUsageReportingEnabled()) return;
160174

161175
let bsConfig = args.bstack_config;
162-
let [cli_version, cli_path] = cli_version_and_path(bsConfig);
176+
let cli_details = cli_version_and_path(bsConfig);
163177

164178
delete args.bstack_config;
165179

@@ -170,8 +184,8 @@ function send(args) {
170184
os_version: os_version(),
171185
bstack_json_found_in_pwd: bstack_json_found_in_pwd(),
172186
cypress_json_found_in_pwd: cypress_json_found_in_pwd(),
173-
cli_version: cli_version,
174-
cli_path: cli_path,
187+
cli_version: cli_details.version,
188+
cli_path: cli_details.path,
175189
npm_version: npm_version(),
176190
local_cypress_version: local_cypress_version(bsConfig),
177191
ci_environment: ci_environment(),

0 commit comments

Comments
 (0)