diff --git a/pkgs/clan-app/ui/src/api/index.tsx b/pkgs/clan-app/ui/src/api/index.tsx index ca652b0ec..531448f53 100644 --- a/pkgs/clan-app/ui/src/api/index.tsx +++ b/pkgs/clan-app/ui/src/api/index.tsx @@ -88,6 +88,20 @@ const handleCancel = async ( ) => { console.log("Canceling operation: ", ops_key); const { promise, op_key } = _callApi("cancel_task", { task_id: ops_key }); + promise.catch((error) => { + toast.custom( + (t) => ( + + ), + { + duration: 5000, + }, + ); + console.error("Unhandled promise rejection in callApi:", error); + }); const resp = await promise; if (resp.status === "error") { @@ -109,13 +123,27 @@ const handleCancel = async ( console.log("Cancel response: ", resp); }; -export const callApi = async ( +export const callApi = ( method: K, args: OperationArgs, -): Promise> => { +): { promise: Promise>; op_key: string } => { console.log("Calling API", method, args); const { promise, op_key } = _callApi(method, args); + promise.catch((error) => { + toast.custom( + (t) => ( + + ), + { + duration: 5000, + }, + ); + console.error("Unhandled promise rejection in callApi:", error); + }); const toastId = toast.custom( ( @@ -132,28 +160,30 @@ export const callApi = async ( }, ); - const response = await promise; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const cancelled = (promise as any).cancelled; - if (cancelled) { - console.log("Not printing toast because operation was cancelled"); - } + const new_promise = promise.then((response) => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const cancelled = (promise as any).cancelled; + if (cancelled) { + console.log("Not printing toast because operation was cancelled"); + } - if (response.status === "error" && !cancelled) { - toast.remove(toastId); - toast.custom( - (t) => ( - - ), - { - duration: Infinity, - }, - ); - } else { - toast.remove(toastId); - } - return response as OperationResponse; + if (response.status === "error" && !cancelled) { + toast.remove(toastId); + toast.custom( + (t) => ( + + ), + { + duration: Infinity, + }, + ); + } else { + toast.remove(toastId); + } + return response; + }); + return { promise: new_promise, op_key: op_key }; }; diff --git a/pkgs/clan-app/ui/src/api/manual_types.tsx b/pkgs/clan-app/ui/src/api/manual_types.tsx deleted file mode 100644 index 7316a63c3..000000000 --- a/pkgs/clan-app/ui/src/api/manual_types.tsx +++ /dev/null @@ -1,10 +0,0 @@ -export interface Machine { - machine: { - name: string; - flake: { - identifier: string; - }; - override_target_host: string | null; - private_key: string | null; - }; -} diff --git a/pkgs/clan-app/ui/src/api/wifi.ts b/pkgs/clan-app/ui/src/api/wifi.ts index 0de237e8d..8e84776e2 100644 --- a/pkgs/clan-app/ui/src/api/wifi.ts +++ b/pkgs/clan-app/ui/src/api/wifi.ts @@ -7,7 +7,7 @@ export const instance_name = (machine_name: string) => export async function get_iwd_service(base_path: string, machine_name: string) { const r = await callApi("get_inventory", { flake: { identifier: base_path }, - }); + }).promise; if (r.status == "error") { return null; } diff --git a/pkgs/clan-app/ui/src/api_test.tsx b/pkgs/clan-app/ui/src/api_test.tsx index 7a18c69ec..c49755e0b 100644 --- a/pkgs/clan-app/ui/src/api_test.tsx +++ b/pkgs/clan-app/ui/src/api_test.tsx @@ -142,11 +142,25 @@ export const ApiTester = () => { {(field, fieldProps) => ( - +
+ +