@@ -14,6 +14,18 @@ export default class httpClient {
14
14
username : string ;
15
15
accessKey : string ;
16
16
17
+ private handleHttpError ( error : any , log : Logger ) : never {
18
+ if ( error && error . response ) {
19
+ log . debug ( `http response error: ${ JSON . stringify ( {
20
+ status : error . response . status ,
21
+ body : error . response . data
22
+ } ) } `) ;
23
+ throw new Error ( error . response . data ?. message || error . response . data || `HTTP ${ error . response . status } error` ) ;
24
+ }
25
+ log . debug ( `http request failed: ${ error . message } ` ) ;
26
+ throw new Error ( error . message ) ;
27
+ }
28
+
17
29
constructor ( { SMARTUI_CLIENT_API_URL , PROJECT_TOKEN , PROJECT_NAME , LT_USERNAME , LT_ACCESS_KEY , SMARTUI_API_PROXY , SMARTUI_API_SKIP_CERTIFICATES } : Env ) {
18
30
this . projectToken = PROJECT_TOKEN || '' ;
19
31
this . projectName = PROJECT_NAME || '' ;
@@ -83,6 +95,8 @@ export default class httpClient {
83
95
84
96
// If we've reached max retries, reject with the error
85
97
return Promise . reject ( error ) ;
98
+ } else {
99
+ return Promise . reject ( error ) ;
86
100
}
87
101
}
88
102
) ;
@@ -644,4 +658,66 @@ export default class httpClient {
644
658
}
645
659
} , ctx . log ) ;
646
660
}
661
+
662
+ async uploadPdf ( ctx : Context , form : FormData , buildName ?: string ) : Promise < any > {
663
+ form . append ( 'projectToken' , this . projectToken ) ;
664
+ if ( ctx . build . name !== undefined && ctx . build . name !== '' ) {
665
+ form . append ( 'buildName' , buildName ) ;
666
+ }
667
+
668
+ try {
669
+ const response = await this . axiosInstance . request ( {
670
+ url : ctx . env . SMARTUI_UPLOAD_URL + '/pdf/upload' ,
671
+ method : 'POST' ,
672
+ headers : form . getHeaders ( ) ,
673
+ data : form ,
674
+ } ) ;
675
+
676
+ ctx . log . debug ( `http response: ${ JSON . stringify ( {
677
+ status : response . status ,
678
+ headers : response . headers ,
679
+ body : response . data
680
+ } ) } `) ;
681
+
682
+ return response . data ;
683
+ } catch ( error : any ) {
684
+ this . handleHttpError ( error , ctx . log ) ;
685
+ }
686
+ }
687
+
688
+ async fetchPdfResults ( ctx : Context ) : Promise < any > {
689
+ const params : Record < string , string > = { } ;
690
+
691
+ if ( ctx . build . projectId ) {
692
+ params . project_id = ctx . build . projectId ;
693
+ } else {
694
+ throw new Error ( 'Project ID not found to fetch PDF results' ) ;
695
+ }
696
+ params . build_id = ctx . build . id ;
697
+
698
+ const auth = Buffer . from ( `${ this . username } :${ this . accessKey } ` ) . toString ( 'base64' ) ;
699
+
700
+ try {
701
+ const response = await axios . request ( {
702
+ url : ctx . env . SMARTUI_UPLOAD_URL + '/smartui/2.0/build/screenshots' ,
703
+ method : 'GET' ,
704
+ params : params ,
705
+ headers : {
706
+ 'accept' : 'application/json' ,
707
+ 'Authorization' : `Basic ${ auth } `
708
+ }
709
+ } ) ;
710
+
711
+ ctx . log . debug ( `http response: ${ JSON . stringify ( {
712
+ status : response . status ,
713
+ headers : response . headers ,
714
+ body : response . data
715
+ } ) } `) ;
716
+
717
+ return response . data ;
718
+ } catch ( error : any ) {
719
+ this . handleHttpError ( error , ctx . log ) ;
720
+ }
721
+ }
647
722
}
723
+
0 commit comments