Skip to content

Commit

Permalink
Fixed redirect when terminal closed
Browse files Browse the repository at this point in the history
  • Loading branch information
tangxianyun committed Jan 13, 2025
1 parent 5296274 commit 83b7ce5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export const TerminalView = ({ terminal }: TerminalViewProps) => {

const activeTerminal = useTerminalStore((state) => state.activeTerminal);
const removeTerminal = useTerminalStore((state) => state.removeTerminal);
const setActiveTerminal = useTerminalStore(
(state) => state.setActiveTerminal
);

const theme = useTheme();
const resize = useDebounceCallback(() => fitAddon.current.fit(), 100);
Expand Down Expand Up @@ -192,7 +195,7 @@ export const TerminalView = ({ terminal }: TerminalViewProps) => {

useEffect(() => {
if (isError) {
setStatus(StatusType.ConnectionError)
setStatus(StatusType.ConnectionError);
}
}, [isError]);

Expand All @@ -205,6 +208,7 @@ export const TerminalView = ({ terminal }: TerminalViewProps) => {

const handleTerminalClose = async () => {
removeTerminal(terminal);
setActiveTerminal(null);
};

const handleAgentClose = async () => {
Expand All @@ -227,6 +231,7 @@ export const TerminalView = ({ terminal }: TerminalViewProps) => {
} else {
await futureService.stopFuture(terminal);
removeTerminal(terminal);
setActiveTerminal(null);
}
};

Expand Down
17 changes: 15 additions & 2 deletions src/core/invoker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,20 @@ export const invoker = async <T>(
const { data } = await invoke<{ data: T }>(command, args);
return data;
} catch (e) {
console.error(e);
throw new InvokerError(JSON.parse(e as string).error);
let errorMessage: string;
if (typeof e === "string") {
try {
const parsedError = JSON.parse(e);
errorMessage = parsedError.error || "Unknown error occurred.";
} catch {
errorMessage = e;
}
} else if (e instanceof Error) {
errorMessage = e.message;
} else {
errorMessage = "An unknown error occurred.";
}

throw new InvokerError(errorMessage);
}
};

0 comments on commit 83b7ce5

Please sign in to comment.