Skip to content

Commit

Permalink
add 6s timeout (#865)
Browse files Browse the repository at this point in the history
  • Loading branch information
UnchartedBull committed Jul 31, 2020
1 parent e4d1c44 commit 1c8d8fc
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 1c8d8fc

Please sign in to comment.