Skip to content

Commit

Permalink
add 6s timeout (UnchartedBull#865)
Browse files Browse the repository at this point in the history
  • Loading branch information
UnchartedBull authored and kantlivelong committed May 5, 2021
1 parent 312b4e4 commit 6073e60
Showing 1 changed file with 9 additions and 0 deletions.
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

0 comments on commit 6073e60

Please sign in to comment.