@@ -467,27 +467,27 @@ export class JiraApiService {
467
467
transform : any ,
468
468
jiraCfg : JiraCfg ,
469
469
) : Observable < any > {
470
- if ( ! this . _isExtension ) {
471
- return fromPromise (
472
- fetch ( url , requestInit )
473
- . then ( ( response ) => response . body )
474
- . then ( streamToJsonIfPossible as any )
475
- . then ( ( res ) => {
476
- if ( ( res as any ) ?. errorMessages ?. length ) {
477
- throw new Error ( ( res as any ) . errorMessages . join ( ', ' ) ) ;
478
- }
479
- return transform ? transform ( { response : res } , jiraCfg ) : { response : res } ;
480
- } ) ,
481
- ) . pipe (
482
- catchError ( ( err ) => {
483
- console . log ( err ) ;
484
- console . log ( getErrorTxt ( err ) ) ;
485
- const errTxt = `Jira: ${ getErrorTxt ( err ) } ` ;
486
- this . _snackService . open ( { type : 'ERROR' , msg : errTxt } ) ;
487
- return throwError ( { [ HANDLED_ERROR_PROP_STR ] : errTxt } ) ;
488
- } ) ,
489
- ) ;
490
- }
470
+ // if (!this._isExtension) {
471
+ // return fromPromise(
472
+ // fetch(url, requestInit)
473
+ // .then((response) => response.body)
474
+ // .then(streamToJsonIfPossible as any)
475
+ // .then((res) => {
476
+ // if ((res as any)?.errorMessages?.length) {
477
+ // throw new Error((res as any).errorMessages.join(', '));
478
+ // }
479
+ // return transform ? transform({ response: res }, jiraCfg) : { response: res };
480
+ // }),
481
+ // ).pipe(
482
+ // catchError((err) => {
483
+ // console.log(err);
484
+ // console.log(getErrorTxt(err));
485
+ // const errTxt = `Jira: ${getErrorTxt(err)}`;
486
+ // this._snackService.open({ type: 'ERROR', msg: errTxt });
487
+ // return throwError({ [HANDLED_ERROR_PROP_STR]: errTxt });
488
+ // }),
489
+ // );
490
+ // }
491
491
492
492
// TODO refactor to observable for request canceling etc
493
493
let promiseResolve ;
@@ -703,32 +703,32 @@ export class JiraApiService {
703
703
}
704
704
}
705
705
706
- // eslint-disable-next-line prefer-arrow/prefer-arrow-functions
707
- async function streamToString ( stream : ReadableStream ) : Promise < string > {
708
- const reader = stream . getReader ( ) ;
709
- const decoder = new TextDecoder ( ) ;
710
- let result = '' ;
711
- let done = false ;
712
-
713
- while ( ! done ) {
714
- const { value, done : doneReading } = await reader . read ( ) ;
715
- done = doneReading ;
716
- if ( value ) {
717
- result += decoder . decode ( value , { stream : true } ) ;
718
- }
719
- }
720
-
721
- result += decoder . decode ( ) ; // flush the decoder
722
- return result ;
723
- }
724
-
725
- // eslint-disable-next-line prefer-arrow/prefer-arrow-functions
726
- async function streamToJsonIfPossible ( stream : ReadableStream ) : Promise < any > {
727
- const text = await streamToString ( stream ) ;
728
- try {
729
- return JSON . parse ( text ) ;
730
- } catch ( e ) {
731
- console . error ( 'Jira: Could not parse response' , text ) ;
732
- return text ;
733
- }
734
- }
706
+ // // eslint-disable-next-line prefer-arrow/prefer-arrow-functions
707
+ // async function streamToString(stream: ReadableStream): Promise<string> {
708
+ // const reader = stream.getReader();
709
+ // const decoder = new TextDecoder();
710
+ // let result = '';
711
+ // let done = false;
712
+ //
713
+ // while (!done) {
714
+ // const { value, done: doneReading } = await reader.read();
715
+ // done = doneReading;
716
+ // if (value) {
717
+ // result += decoder.decode(value, { stream: true });
718
+ // }
719
+ // }
720
+ //
721
+ // result += decoder.decode(); // flush the decoder
722
+ // return result;
723
+ // }
724
+ //
725
+ // // eslint-disable-next-line prefer-arrow/prefer-arrow-functions
726
+ // async function streamToJsonIfPossible(stream: ReadableStream): Promise<any> {
727
+ // const text = await streamToString(stream);
728
+ // try {
729
+ // return JSON.parse(text);
730
+ // } catch (e) {
731
+ // console.error('Jira: Could not parse response', text);
732
+ // return text;
733
+ // }
734
+ // }
0 commit comments