diff --git a/src/routes/terminal.ts b/src/routes/terminal.ts index 10090d5..4f11314 100644 --- a/src/routes/terminal.ts +++ b/src/routes/terminal.ts @@ -2,7 +2,7 @@ import yaml from 'js-yaml'; import { throttle, uniqBy } from 'lodash'; import { spawn } from 'node-pty'; import os from 'os'; -import { Router, RouterResponse } from 'soxtend/server'; +import { ApiError, Router, RouterResponse } from 'soxtend/server'; import kill from 'tree-kill'; import { AppDataSource, ProjectRepository, TerminalLogRepository, TerminalRepository } from '../data-source'; import { Terminal } from '../entity/Terminal'; @@ -97,12 +97,12 @@ export const addTerminalRoutes = (router: Router) => { if (Object.keys(terminal).length === 0) return; if (terminal.startupEnvironmentVariables) { try { - yaml.load(terminal.startupEnvironmentVariables, { + const doc = yaml.load(terminal.startupEnvironmentVariables, { schema: yaml.JSON_SCHEMA, }); + if (typeof doc !== 'object') throw new ApiError('Invalid YAML for startup Environment Variables', 400); } catch (e) { - console.log('error', e); - throw new Error('Invalid YAML for startup Environment Variables'); + throw new ApiError('Invalid YAML for startup Environment Variables', 400); } } // This prevents from updating terminal object in the triggering app unnecessary. @@ -217,7 +217,7 @@ function createPtyTerminal({ }) as Record; env = { ...(process.env as Record), ...doc }; } catch (e) { - throw new Error('Invalid YAML for startup Environment Variables'); + console.log(e); } let cwd = terminal.cwd; if (cwd) { diff --git a/ui/src/pages/MyTerminal/MyTerminal.tsx b/ui/src/pages/MyTerminal/MyTerminal.tsx index 0f1dc2b..6014b67 100644 --- a/ui/src/pages/MyTerminal/MyTerminal.tsx +++ b/ui/src/pages/MyTerminal/MyTerminal.tsx @@ -2,7 +2,7 @@ import { debounce } from 'lodash-es'; import { useCallback, useContext, useEffect, useMemo, useReducer } from 'react'; import { client } from '../../utils/socket'; import { Addons, createTerminal } from '../../utils/Terminal'; -import { Drawer, Input, Modal, AutoComplete, Form } from 'antd'; +import { Drawer, Input, Modal, AutoComplete, Form, Alert } from 'antd'; import './MyTerminal.css'; // @ts-ignore @@ -130,7 +130,7 @@ export const MyTerminal = ({ mainCommandCounter: number; }) => { const [isPatching, setIsPatching] = useState(false); - const { mutate: patchTerminal } = usePatchTerminal(projectId, terminal.id); + const { mutate: patchTerminal, error } = usePatchTerminal(projectId, terminal.id); const [editorCommand, setEditorCommand] = useState(''); const [isCommandSuggestionOpen, setIsCommandSuggestionOpen] = useState(false); @@ -422,6 +422,7 @@ export const MyTerminal = ({ }); }, [searchValue, state]); if (!state) return null; + console.log(error); return ( <> setExecutionScript(null)}> @@ -568,6 +569,7 @@ export const MyTerminal = ({ > + {error && } diff --git a/ui/src/services/terminals.ts b/ui/src/services/terminals.ts index bb8e603..c5ede00 100644 --- a/ui/src/services/terminals.ts +++ b/ui/src/services/terminals.ts @@ -115,10 +115,6 @@ export const usePatchTerminal = ( method: 'patch', }), { - retry: (_, error) => { - if (error.status === 401) return false; - return true; - }, ...options, } );