diff --git a/.changeset/khaki-rockets-switch.md b/.changeset/khaki-rockets-switch.md new file mode 100644 index 0000000000..de54f16036 --- /dev/null +++ b/.changeset/khaki-rockets-switch.md @@ -0,0 +1,6 @@ +--- +"@scow/portal-web": patch +"@scow/lib-ssh": patch +--- + +sshConnect 时,提示语过长会使得连接失败,现在捕获了这个错误并提示用户 diff --git a/apps/portal-server/src/utils/ssh.ts b/apps/portal-server/src/utils/ssh.ts index 648dec3eaf..e23eeae3ba 100644 --- a/apps/portal-server/src/utils/ssh.ts +++ b/apps/portal-server/src/utils/ssh.ts @@ -88,7 +88,7 @@ export async function sshConnect( code: status.INTERNAL, details: e.message, message: e.message, - metadata: scowErrorMetadata(SSH_ERROR_CODE), + metadata: scowErrorMetadata(SSH_ERROR_CODE, typeof e.cause === "string" ? { cause:e.cause } : undefined), }); } diff --git a/apps/portal-web/src/i18n/en.ts b/apps/portal-web/src/i18n/en.ts index 2e836482e7..0626bd6bac 100644 --- a/apps/portal-web/src/i18n/en.ts +++ b/apps/portal-web/src/i18n/en.ts @@ -457,6 +457,8 @@ export default { _app: { sshError: "Unable to connect as a user to the login node. Please make sure the permissions " + "of your home directory are 700, 750, or 755.", + textExceedsLength:"There are too many welcome messages for terminal login." + + "Please reduce unnecessary information output!", sftpError: "SFTP operation failed. Please confirm if you have the necessary permissions.", otherError: "Server encountered an error!", }, diff --git a/apps/portal-web/src/i18n/zh_cn.ts b/apps/portal-web/src/i18n/zh_cn.ts index db1a0c3b51..48bc10d0be 100644 --- a/apps/portal-web/src/i18n/zh_cn.ts +++ b/apps/portal-web/src/i18n/zh_cn.ts @@ -455,8 +455,8 @@ export default { }, }, _app: { + textExceedsLength:"终端登录欢迎提示信息过多,请减少不必要的信息输出!", sshError:"无法以用户身份连接到登录节点。请确认您的家目录的权限为700、750或者755", - sftpError:"SFTP操作失败,请确认您是否有操作的权限", otherError:"服务器出错啦!", }, diff --git a/apps/portal-web/src/pages/_app.tsx b/apps/portal-web/src/pages/_app.tsx index 08cc685b0b..cdaef4ea39 100644 --- a/apps/portal-web/src/pages/_app.tsx +++ b/apps/portal-web/src/pages/_app.tsx @@ -59,11 +59,18 @@ const FailEventHandler: React.FC = () => { return; } + const regex = /exceeds max length/; + // 如果终端登录欢迎语过长会报错:Packet length xxxx exceeds max length of 262144 + if (regex.test(e.data?.message)) { + message.error(t("pages._app.textExceedsLength")); + return; + } + if (e.data?.code === "SSH_ERROR") { message.error(t("pages._app.sshError")); return; } - + if (e.data?.code === "SFTP_ERROR") { message.error(e.data?.details.length > 150 ? e.data?.details.substring(0, 150) + "..." : e.data?.details || t("pages._app.sftpError")); diff --git a/apps/portal-web/src/utils/route.ts b/apps/portal-web/src/utils/route.ts index 96ac23e479..2a515904e0 100644 --- a/apps/portal-web/src/utils/route.ts +++ b/apps/portal-web/src/utils/route.ts @@ -21,11 +21,13 @@ export const route: typeof typeboxRoute = (schema, handler) => { if (!(e.metadata instanceof Metadata)) { throw e; } const SCOW_ERROR = (e.metadata as Metadata).get("IS_SCOW_ERROR"); + const SCOW_CAUSE = (e.metadata as Metadata).get("cause"); if (SCOW_ERROR.length === 0) { throw e; } const code = e.metadata.get("SCOW_ERROR_CODE")[0].toString(); const details = e.details; - return { 500: { code, details } } as any; + const message = SCOW_CAUSE[0]; + return { 500: { code, details, message } } as any; }); } }); diff --git a/libs/ssh/src/ssh.ts b/libs/ssh/src/ssh.ts index 1164c618ef..8969fbbac9 100644 --- a/libs/ssh/src/ssh.ts +++ b/libs/ssh/src/ssh.ts @@ -93,7 +93,18 @@ export async function sshConnect( ) { const ssh = await sshRawConnect(address, username, rootKeyPair, logger); - return run(ssh).finally(() => { ssh.dispose(); }); + return run(ssh) + .catch((e) => { + // 若在run回调函数中有具体抛错,直接抛出 + if (e.code !== undefined) { + throw e; + } + else { + logger.info("Running ssh failed."); + throw new SshConnectError({ cause: e.message }); + } + }) + .finally(() => { ssh.dispose(); }); } export async function sshConnectByPassword(