File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change 1
1
const debug = require ( 'debug' ) ( 'codefresh:http' ) ;
2
2
const rp = require ( 'request-promise' ) ;
3
3
const _ = require ( 'lodash' ) ;
4
+ const { printError } = require ( '../../interface/cli/helpers/general' ) ;
4
5
5
6
const sendHttpRequest = async ( httpOptions , authContext ) => {
6
7
let finalAuthContext ;
@@ -13,7 +14,19 @@ const sendHttpRequest = async (httpOptions, authContext) => {
13
14
14
15
const finalOptions = _ . assignIn ( httpOptions , finalAuthContext . prepareHttpOptions ( ) , { json : true } ) ;
15
16
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
+ }
17
30
debug ( 'Response:\n%O' , response ) ;
18
31
return response ;
19
32
} ;
You can’t perform that action at this time.
0 commit comments