UNPKG

@xtail/ssh

Version:

X-Tail SSH 库,包含 SSH 连接服务器的类和工具方法等

51 lines (50 loc) 1.72 kB
import { SSHErrorCodeConst as e } from "../consts/ssh-error-code.js"; import { SSHErrorMsgMap as s } from "../maps/ssh-error-msg.js"; const m = (N, t = {}) => { var O, l; let E = "未知错误", a = ""; if (N.code) switch (N.code) { // 连接类错误 case e.ECONNREFUSED: E = s[e.ECONNREFUSED].message, a = s[e.ECONNREFUSED].detail; break; case e.ETIMEDOUT: E = s[e.ETIMEDOUT].message, a = s[e.ETIMEDOUT].detail; break; case e.EHOSTUNREACH: E = s[e.EHOSTUNREACH].message, a = s[e.EHOSTUNREACH].detail; break; case e.EAUTH: E = s[e.EAUTH].message, a = s[e.EAUTH].detail; break; // 命令执行类错误 case e.ENOENT: E = s[e.ENOENT].message, a = s[e.ENOENT].detail; break; case e.EACCES: E = s[e.EACCES].message, a = s[e.EACCES].detail; break; // SFTP 类错误 case e.NO_SUCH_FILE: E = s[e.NO_SUCH_FILE].message, a = s[e.NO_SUCH_FILE].detail; break; case e.PERMISSION_DENIED: E = s[e.PERMISSION_DENIED].message, a = s[e.PERMISSION_DENIED].detail; break; // 未知错误 default: E = s[e.UNKNOWN].message, a = s[e.UNKNOWN].detail + (" " + N.stack || ""); break; } else (O = N.message) != null && O.includes("time out") || (l = N.message) != null && l.includes("timed out") ? (E = s[e.ETIMEDOUT].message, a = s[e.ETIMEDOUT].detail) : (E = s[e.UNKNOWN].message, a = s[e.UNKNOWN].detail + (" " + N.message || JSON.stringify(N))); return { success: !1, server: `${t.host || "localhost"}:${t.port || 22}`, message: E, detail: a }; }; export { m as errorHandler };