Skip to content

Commit 533d70b

Browse files
ziv-codefreshitai-codefresh
authored andcommitted
Support showing errors in case of authentication errors (#55)
1 parent fe5c106 commit 533d70b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/logic/api/helper.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const debug = require('debug')('codefresh:http');
22
const rp = require('request-promise');
33
const _ = require('lodash');
4+
const { printError } = require('../../interface/cli/helpers/general');
45

56
const sendHttpRequest = async (httpOptions, authContext) => {
67
let finalAuthContext;
@@ -13,7 +14,19 @@ const sendHttpRequest = async (httpOptions, authContext) => {
1314

1415
const finalOptions = _.assignIn(httpOptions, finalAuthContext.prepareHttpOptions(), { json: true });
1516
debug('Sending http request:\n%O', finalOptions);
16-
const response = await rp(finalOptions);
17+
let response;
18+
try {
19+
response = await rp(finalOptions);
20+
} catch (err) {
21+
if (_.isEqual(err.statusCode, 401)) {
22+
printError('Unauthorized error: Please update your authentication context');
23+
process.exit(1);
24+
}
25+
if (_.isEqual(err.statusCode, 403)) {
26+
printError('Forbidden error: You do not have permissions to perform this action');
27+
process.exit(1);
28+
}
29+
}
1730
debug('Response:\n%O', response);
1831
return response;
1932
};

0 commit comments

Comments
 (0)