1
1
const https = require ( 'https' ) ;
2
2
const _ = require ( 'lodash' ) ;
3
3
const axios = require ( 'axios' ) ;
4
- const { } = require ( '../utils/cmdPrint' ) ;
4
+ const { jestAuthFileGenerationLog } = require ( '../utils/cmdPrint' ) ;
5
5
const args = require ( '../utils/getArgs.js' ) ;
6
6
7
7
function extractGPTMessageFromStreamData ( input ) {
@@ -38,12 +38,19 @@ function setOptions({protocol, hostname, port, path, method, headers}) {
38
38
39
39
async function makeRequest ( data , options ) {
40
40
let gptResponse = '' ;
41
+ let end = false ;
41
42
42
43
return new Promise ( ( resolve , reject ) => {
43
44
const req = https . request ( _ . omit ( options , [ 'protocol' ] ) , function ( res ) {
44
45
res . on ( 'data' , ( chunk ) => {
45
46
try {
46
47
let stringified = chunk . toString ( ) ;
48
+ if ( stringified === 'pythagora_end' ) {
49
+ gptResponse = '' ;
50
+ end = true ;
51
+ return ;
52
+ }
53
+ if ( end ) return gptResponse = stringified ;
47
54
try {
48
55
let json = JSON . parse ( stringified ) ;
49
56
if ( json . error ) gptResponse = json . error ;
@@ -60,8 +67,9 @@ async function makeRequest(data, options) {
60
67
61
68
} catch ( e ) { }
62
69
} ) ;
63
- res . on ( 'end' , async ( ) => {
64
- if ( res . statusCode >= 400 ) throw new Error ( `Response status code: ${ res . statusCode } .` ) ;
70
+ res . on ( 'end' , async ( a , b , c ) => {
71
+ process . stdout . write ( '\n' ) ;
72
+ if ( res . statusCode >= 400 ) throw new Error ( `Response status code: ${ res . statusCode } . Error message: ${ gptResponse } ` ) ;
65
73
if ( gptResponse . message ) throw new Error ( `Error: ${ gptResponse . message } . Code: ${ gptResponse . code } ` ) ;
66
74
gptResponse = cleanupGPTResponse ( gptResponse ) ;
67
75
resolve ( gptResponse ) ;
@@ -102,7 +110,7 @@ async function isEligibleForExport(jestTest) {
102
110
let options = setOptions ( { path : '/check-if-eligible' } ) ;
103
111
104
112
const response = await axios . post (
105
- `${ options . protocol } ://${ options . hostname } : ${ options . port } ${ options . path } ` ,
113
+ `${ options . protocol } ://${ options . hostname } ${ options . port ? ':' + options . port : '' } ${ options . path } ` ,
106
114
JSON . stringify ( { jestTest } ) ,
107
115
{ headers : options . headers }
108
116
) ;
0 commit comments