web/saving-handler: refactor error dialog handling

& remove debug logging for local processing
This commit is contained in:
wukko 2025-05-14 15:26:39 +06:00
parent 68e8b3369d
commit 700067c4ec
No known key found for this signature in database
GPG Key ID: 3E30B3F26C7B4AA2

View File

@ -9,25 +9,26 @@ import { createDialog } from "$lib/state/dialogs";
import { downloadButtonState } from "$lib/state/omnibox"; import { downloadButtonState } from "$lib/state/omnibox";
import { createSavePipeline } from "$lib/task-manager/queue"; import { createSavePipeline } from "$lib/task-manager/queue";
import type { DialogInfo } from "$lib/types/dialog";
import type { CobaltSaveRequestBody } from "$lib/types/api"; import type { CobaltSaveRequestBody } from "$lib/types/api";
const defaultErrorPopup: DialogInfo = {
id: "save-error",
type: "small",
meowbalt: "error",
};
export const savingHandler = async ({ url, request }: { url?: string, request?: CobaltSaveRequestBody }) => { export const savingHandler = async ({ url, request }: { url?: string, request?: CobaltSaveRequestBody }) => {
downloadButtonState.set("think"); downloadButtonState.set("think");
const errorButtons = [ const error = (errorText: string) => {
return createDialog({
id: "save-error",
type: "small",
meowbalt: "error",
buttons: [
{ {
text: get(t)("button.gotit"), text: get(t)("button.gotit"),
main: true, main: true,
action: () => {}, action: () => {},
}, },
]; ],
bodyText: errorText,
});
}
const getSetting = lazySettingGetter(get(settings)); const getSetting = lazySettingGetter(get(settings));
@ -63,22 +64,15 @@ export const savingHandler = async ({ url, request }: { url?: string, request?:
if (!response) { if (!response) {
downloadButtonState.set("error"); downloadButtonState.set("error");
return error(get(t)("error.api.unreachable"));
return createDialog({
...defaultErrorPopup,
buttons: errorButtons,
bodyText: get(t)("error.api.unreachable"),
});
} }
if (response.status === "error") { if (response.status === "error") {
downloadButtonState.set("error"); downloadButtonState.set("error");
return createDialog({ return error(
...defaultErrorPopup, get(t)(response.error.code, response?.error?.context)
buttons: errorButtons, );
bodyText: get(t)(response.error.code, response?.error?.context),
});
} }
if (response.status === "redirect") { if (response.status === "redirect") {
@ -103,19 +97,11 @@ export const savingHandler = async ({ url, request }: { url?: string, request?:
}); });
} else { } else {
downloadButtonState.set("error"); downloadButtonState.set("error");
return error(get(t)("error.tunnel.probe"));
return createDialog({
...defaultErrorPopup,
buttons: errorButtons,
bodyText: get(t)("error.tunnel.probe"),
});
} }
} }
if (response.status === "local-processing") { if (response.status === "local-processing") {
// TODO: remove debug logging
console.log(response);
downloadButtonState.set("done"); downloadButtonState.set("done");
return createSavePipeline(response, selectedRequest); return createSavePipeline(response, selectedRequest);
} }
@ -152,9 +138,5 @@ export const savingHandler = async ({ url, request }: { url?: string, request?:
} }
downloadButtonState.set("error"); downloadButtonState.set("error");
return createDialog({ return error(get(t)("error.api.unknown_response"));
...defaultErrorPopup,
buttons: errorButtons,
bodyText: get(t)("error.api.unknown_response"),
});
} }