Skip to content

Commit

Permalink
Improve error handling for failed downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvinn8 committed Mar 25, 2024
1 parent ce128cc commit 5f161ab
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/common/contextmenu/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ import TaskManager from "../task/TaskManager";
import { getApp } from "../ui/App";

export async function downloadFolderEntry(entry: FolderEntry) {
const blob = await getApp().state.session.download(Priority.QUICK, entry);
download(blob, entry.name);
try {
const blob = await getApp().state.session.download(Priority.QUICK, entry);
download(blob, entry.name);
} catch(e) {
Dialog.message("Failed to download", String(e));
}
}

export function rename(entry: FolderEntry) {
Expand Down
10 changes: 8 additions & 2 deletions src/common/ui/editor/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export async function openNbtEditor(folderEntry: FolderEntry) {
} catch(e) {
Dialog.message(
"Error reading NBT",
"There was an error reading the NBT file. Are you sure it is an NBT file? " + e
"There was an error reading the NBT file. " + String(e)
);
return;
}
Expand Down Expand Up @@ -299,7 +299,13 @@ async function getFile(folderEntry: FolderEntry): Promise<EditorFileInfo | null>
const isgzipped = folderEntry.name.endsWith(".gz");
if (isgzipped && !await confirmOpenGzip(folderEntry)) return null;

let blob = await getApp().state.session.download(Priority.QUICK, folderEntry);
let blob;
try {
blob = await getApp().state.session.download(Priority.QUICK, folderEntry)
} catch(e) {
Dialog.message("Failed to open file", String(e));
return null;
}
if (isgzipped) {
blob = await ungzip(blob);
return {
Expand Down
2 changes: 1 addition & 1 deletion src/web/WebsocketFTPConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export default class WebsocketFTPConnection implements FTPConnection {
xhr.open("GET", url);
xhr.send();
});
} else if (response.data) {
} else if (response.data || response.data === '') {
const base64 = response.data;
const binarystring = atob(base64);
const arraybuffer = new Uint8Array(binarystring.length);
Expand Down

0 comments on commit 5f161ab

Please sign in to comment.