@@ -18,23 +18,28 @@ const ignores = ['.git', 'node_modules'];
1818
1919const streamToResponse = ( { tarStream, remoteUrl, options} ) =>
2020 new Promise ( ( resolve , reject ) => {
21- // pipe stream to remote
21+ // store error and result
22+ let error ;
2223 let result = '' ;
24+ // pipe stream to remote
2325 const stream = tarStream . pipe ( got . stream . post ( remoteUrl , options ) ) ;
24- // log output if in verbose mode
26+ // store output
2527 stream . on ( 'data' , str => ( result += str . toString ( ) ) ) ;
2628 // listen for read stream end
2729 stream . on ( 'end' , ( ) => {
2830 const res = JSON . parse ( result ) ;
29- // ignore errored out results
30- if ( res . status !== 'success' ) {
31+ // if stream had error - reject
32+ if ( error ) {
33+ // add response to allow access to body
34+ error . response = res ;
35+ reject ( error ) ;
3136 return ;
3237 }
33- // resolve on end
38+ // otherwise resolve
3439 resolve ( res ) ;
3540 } ) ;
3641 // listen for stream errors
37- stream . on ( 'error' , e => reject ( e ) ) ;
42+ stream . on ( 'error' , e => ( error = e ) ) ;
3843 } ) ;
3944
4045exports . command = [ '*' , 'deploy' ] ;
@@ -148,14 +153,21 @@ exports.handler = async (args = {}) => {
148153 opn ( `http://${ formattedServices [ 0 ] . domain . split ( ',' ) [ 0 ] . trim ( ) } ` ) ;
149154 }
150155 } catch ( e ) {
151- spinner . fail ( 'Upload failed!' ) ;
156+ spinner . fail ( 'Deployment failed!' ) ;
152157 // if authorization is expired/broken/etc
153158 if ( e . statusCode === 401 ) {
154159 logout ( userConfig ) ;
155160 console . log ( chalk . red ( 'Error: authorization expired!' ) , 'Please, relogin and try again.' ) ;
156161 return ;
157162 }
158163
159- console . log ( chalk . red ( 'Error deploying project:' ) , e . toString ( ) ) ;
164+ const reason = e . response . result ? e . response . result . error : e . toString ( ) ;
165+ console . log ( chalk . red ( 'Error deploying project:' ) , reason ) ;
166+ console . log ( 'Build log:\n' ) ;
167+ e . response . result . log
168+ . filter ( l => l !== undefined )
169+ . map ( l => l . trim ( ) )
170+ . filter ( l => l && l . length > 0 )
171+ . forEach ( line => console . log ( line ) ) ;
160172 }
161173} ;
0 commit comments