Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeout while loading files #865

Merged
merged 1 commit into from
Jul 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/app/files.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { OctoprintFilesAPI, OctoprintFolderAPI, OctoprintFolderContentAPI } from
})
export class FilesService {
private httpGETRequest: Subscription;
private httpGETRequestTimeout: number;
private httpPOSTRequest: Subscription;
private httpDELETERequest: Subscription;

Expand All @@ -25,6 +26,11 @@ export class FilesService {

public getFolder(folderPath = "/"): Promise<(File | Folder)[]> {
return new Promise((resolve, reject): void => {
this.httpGETRequestTimeout = setTimeout(() => {
this.httpGETRequest.unsubscribe();
this.notificationService.setError("Can't retrieve folder!", "Operation timed out. Please try again.");
reject();
}, 6000);
folderPath = folderPath === "/" ? "" : folderPath;
if (this.httpGETRequest) {
this.httpGETRequest.unsubscribe();
Expand Down Expand Up @@ -122,6 +128,9 @@ export class FilesService {
this.notificationService.setError("Can't retrieve folder!", error.message);
reject();
}
},
(): void => {
clearTimeout(this.httpGETRequestTimeout);
}
);
});
Expand Down