@@ -35,7 +35,7 @@ exports.handler = async args => {
35
35
headers : {
36
36
Authorization : `Bearer ${ userConfig . token } ` ,
37
37
} ,
38
- json : true ,
38
+ responseType : 'json' ,
39
39
} ;
40
40
41
41
// if remove or ls - fetch tokens from remote, then do work
@@ -48,11 +48,11 @@ exports.handler = async args => {
48
48
// try sending request
49
49
let templates = [ ] ;
50
50
try {
51
- const { body} = await got ( remoteUrl , baseOptions ) ;
51
+ const { body} = await got ( remoteUrl , { ... baseOptions } ) ;
52
52
templates = body ;
53
53
} catch ( e ) {
54
54
// if authorization is expired/broken/etc
55
- if ( e . statusCode === 401 ) {
55
+ if ( e . response . statusCode === 401 ) {
56
56
logout ( userConfig ) ;
57
57
console . log ( chalk . red ( 'Error: authorization expired!' ) , 'Please, relogin and try again.' ) ;
58
58
return ;
@@ -98,12 +98,14 @@ exports.handler = async args => {
98
98
const { rmTemplate} = await inquirer . prompt ( prompts ) ;
99
99
100
100
// construct shared request params
101
- const rmOptions = Object . assign ( baseOptions , {
101
+ const rmOptions = {
102
+ ...baseOptions ,
102
103
method : 'DELETE' ,
103
- body : {
104
+ json : {
104
105
templateName : rmTemplate ,
105
106
} ,
106
- } ) ;
107
+ responseType : 'json' ,
108
+ } ;
107
109
try {
108
110
const { body} = await got ( remoteUrl , rmOptions ) ;
109
111
if ( ! body . removed ) {
@@ -119,7 +121,7 @@ exports.handler = async args => {
119
121
console . log ( chalk . green ( 'Template successfully removed!' ) ) ;
120
122
} catch ( e ) {
121
123
// if authorization is expired/broken/etc
122
- if ( e . statusCode === 401 ) {
124
+ if ( e . response . statusCode === 401 ) {
123
125
logout ( userConfig ) ;
124
126
console . log ( chalk . red ( 'Error: authorization expired!' ) , 'Please, relogin and try again.' ) ;
125
127
return ;
@@ -146,12 +148,14 @@ exports.handler = async args => {
146
148
const { templateName} = await inquirer . prompt ( prompts ) ;
147
149
148
150
// construct shared request params
149
- const options = Object . assign ( baseOptions , {
151
+ const options = {
152
+ ...baseOptions ,
150
153
method : 'POST' ,
151
- body : {
154
+ json : {
152
155
templateName,
153
156
} ,
154
- } ) ;
157
+ responseType : 'json' ,
158
+ } ;
155
159
156
160
// show loader
157
161
const spinner = ora ( 'Installing new template...' ) . start ( ) ;
@@ -176,7 +180,7 @@ exports.handler = async args => {
176
180
} catch ( e ) {
177
181
spinner . fail ( 'Template install failed!' ) ;
178
182
// if authorization is expired/broken/etc
179
- if ( e . statusCode === 401 ) {
183
+ if ( e . response . statusCode === 401 ) {
180
184
logout ( userConfig ) ;
181
185
console . log ( chalk . red ( 'Error: authorization expired!' ) , 'Please, relogin and try again.' ) ;
182
186
return ;
0 commit comments