@@ -154,18 +154,38 @@ module.exports = {
154154 }
155155 if ( msg . response ) {
156156 if ( msg . response . status === 401 ) {
157- console . warn ( "Not logged in. Use 'login' to log in." ) ;
157+ if ( outputFormat === "json" ) {
158+ console . log ( { error :"Not logged in. Use 'login' to log in." , status : 401 } ) ;
159+ } else {
160+ console . warn ( "Not logged in. Use 'login' to log in." ) ;
161+ }
158162 } else if ( msg . response . data ) {
159163 if ( msg . response . status === 404 && ! msg . response . data . message ) {
160- console . warn ( "Node-RED Admin API not found. Use 'target' to set API location" ) ;
164+ if ( outputFormat === "json" ) {
165+ console . log ( { error :"Node-RED Admin API not found. Use 'target' to set API location" , status : 404 } ) ;
166+ } else {
167+ console . warn ( "Node-RED Admin API not found. Use 'target' to set API location" ) ;
168+ }
161169 } else {
162- console . warn ( msg . response . status + ": " + msg . response . data . message ) ;
170+ if ( outputFormat === "json" ) {
171+ console . log ( { error :msg . response . data . message , status : msg . response . status } ) ;
172+ } else {
173+ console . warn ( msg . response . status + ": " + msg . response . data . message ) ;
174+ }
163175 }
164176 } else {
165- console . warn ( msg . response . status + ": " + msg . toString ( ) ) ;
177+ if ( outputFormat === "json" ) {
178+ console . log ( { error :msg . toString ( ) , status : msg . response . status } ) ;
179+ } else {
180+ console . warn ( msg . response . status + ": " + msg . toString ( ) ) ;
181+ }
166182 }
167183 } else {
168- console . warn ( msg . toString ( ) ) ;
184+ if ( outputFormat === "json" ) {
185+ console . log ( { error :msg . toString ( ) } ) ;
186+ } else {
187+ console . warn ( msg . toString ( ) ) ;
188+ }
169189 }
170190 } ,
171191 help :function ( command ) {
0 commit comments