Skip to content

Commit 264ced7

Browse files
committed
feat(issue): go back to classic way of doing jira requests as it is more reliable
1 parent a33de8c commit 264ced7

File tree

1 file changed

+50
-50
lines changed

1 file changed

+50
-50
lines changed

src/app/features/issue/providers/jira/jira-api.service.ts

+50-50
Original file line numberDiff line numberDiff line change
@@ -467,27 +467,27 @@ export class JiraApiService {
467467
transform: any,
468468
jiraCfg: JiraCfg,
469469
): 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+
// }
491491

492492
// TODO refactor to observable for request canceling etc
493493
let promiseResolve;
@@ -703,32 +703,32 @@ export class JiraApiService {
703703
}
704704
}
705705

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

Comments
 (0)