Skip to content
Snippets Groups Projects
Commit c6c12b05 authored by Florent Poittevin's avatar Florent Poittevin
Browse files

fix: problem when download archive with slow network

parent 2518ecde
No related branches found
No related tags found
No related merge requests found
......@@ -46,6 +46,7 @@ import {
ApiService,
CollectionTyped,
defaultResourceStateInitValue,
ErrorDto,
HttpStatus,
isNullOrUndefined,
isWhiteString,
......@@ -291,22 +292,30 @@ export class HomeState {
});
let pooling: boolean = true;
let pendingRequest: boolean = false;
let firstTimeError: boolean = false;
this.notificationService.showInformation(TRANSLATE("home.archive.browsing.download.notification.inPreparation"), true);
return interval(500)
.pipe(
takeWhile(() => pooling === true),
takeWhile(() => pooling === true && pendingRequest === false),
startWith(0),
mergeMap(() => this.getDownloadStatus(ctx, action.dataFile.resId)),
mergeMap(() => {
pendingRequest = true;
return this.getDownloadStatus(ctx, action.dataFile.resId).pipe(
tap(() => pendingRequest = false),
);
}),
tap((res: string) => {
if (res === StringUtil.stringEmpty) {
this.prepareDownload(ctx, action.dataFile.resId);
return;
}
if (res === Order.StatusEnum.READY) {
this.downloadFile(ctx, action.dataFile.resId);
pooling = false;
return;
}
if (res === Order.StatusEnum.INERROR) {
pooling = false;
......@@ -314,8 +323,14 @@ export class HomeState {
ctx.dispatch(new DownloadFail());
firstTimeError = true;
}
return;
}
}));
}),
catchError(error => {
pooling = false;
throw error;
})
);
}
......@@ -341,8 +356,7 @@ export class HomeState {
headers,
responseType: "text",
}).pipe(
tap((res: string) => res),
catchError((e/*: ErrorDto*/) => {
catchError((e: ErrorDto) => {
if (e.status === HttpStatus.INTERNAL_SERVER_ERROR) {
return of(Order.StatusEnum.INERROR);
}
......
import {Deposit} from "@app/generated-api";
import {StatusEnum} from "@app/generated-api/model/deposit.model";
import {PackageStatusEnum} from "@shared/enums/business/package-status.enum";
import {
KeyValue,
TRANSLATE,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment