@@ -35,7 +35,7 @@ exports.handler = async args => {
3535 headers : {
3636 Authorization : `Bearer ${ userConfig . token } ` ,
3737 } ,
38- json : true ,
38+ responseType : 'json' ,
3939 } ;
4040
4141 // if remove or ls - fetch tokens from remote, then do work
@@ -48,11 +48,11 @@ exports.handler = async args => {
4848 // try sending request
4949 let templates = [ ] ;
5050 try {
51- const { body} = await got ( remoteUrl , baseOptions ) ;
51+ const { body} = await got ( remoteUrl , { ... baseOptions } ) ;
5252 templates = body ;
5353 } catch ( e ) {
5454 // if authorization is expired/broken/etc
55- if ( e . statusCode === 401 ) {
55+ if ( e . response . statusCode === 401 ) {
5656 logout ( userConfig ) ;
5757 console . log ( chalk . red ( 'Error: authorization expired!' ) , 'Please, relogin and try again.' ) ;
5858 return ;
@@ -98,12 +98,14 @@ exports.handler = async args => {
9898 const { rmTemplate} = await inquirer . prompt ( prompts ) ;
9999
100100 // construct shared request params
101- const rmOptions = Object . assign ( baseOptions , {
101+ const rmOptions = {
102+ ...baseOptions ,
102103 method : 'DELETE' ,
103- body : {
104+ json : {
104105 templateName : rmTemplate ,
105106 } ,
106- } ) ;
107+ responseType : 'json' ,
108+ } ;
107109 try {
108110 const { body} = await got ( remoteUrl , rmOptions ) ;
109111 if ( ! body . removed ) {
@@ -119,7 +121,7 @@ exports.handler = async args => {
119121 console . log ( chalk . green ( 'Template successfully removed!' ) ) ;
120122 } catch ( e ) {
121123 // if authorization is expired/broken/etc
122- if ( e . statusCode === 401 ) {
124+ if ( e . response . statusCode === 401 ) {
123125 logout ( userConfig ) ;
124126 console . log ( chalk . red ( 'Error: authorization expired!' ) , 'Please, relogin and try again.' ) ;
125127 return ;
@@ -146,12 +148,14 @@ exports.handler = async args => {
146148 const { templateName} = await inquirer . prompt ( prompts ) ;
147149
148150 // construct shared request params
149- const options = Object . assign ( baseOptions , {
151+ const options = {
152+ ...baseOptions ,
150153 method : 'POST' ,
151- body : {
154+ json : {
152155 templateName,
153156 } ,
154- } ) ;
157+ responseType : 'json' ,
158+ } ;
155159
156160 // show loader
157161 const spinner = ora ( 'Installing new template...' ) . start ( ) ;
@@ -176,7 +180,7 @@ exports.handler = async args => {
176180 } catch ( e ) {
177181 spinner . fail ( 'Template install failed!' ) ;
178182 // if authorization is expired/broken/etc
179- if ( e . statusCode === 401 ) {
183+ if ( e . response . statusCode === 401 ) {
180184 logout ( userConfig ) ;
181185 console . log ( chalk . red ( 'Error: authorization expired!' ) , 'Please, relogin and try again.' ) ;
182186 return ;
0 commit comments