@xtail/ssh
Version:
X-Tail SSH 库,包含 SSH 连接服务器的类和工具方法等
2 lines (1 loc) • 2.12 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../consts/ssh-error-code.js"),o=require("../maps/ssh-error-msg.js"),H=(s,E={})=>{var C,a;let S="未知错误",e="";if(s.code)switch(s.code){case r.SSHErrorCodeConst.ECONNREFUSED:S=o.SSHErrorMsgMap[r.SSHErrorCodeConst.ECONNREFUSED].message,e=o.SSHErrorMsgMap[r.SSHErrorCodeConst.ECONNREFUSED].detail;break;case r.SSHErrorCodeConst.ETIMEDOUT:S=o.SSHErrorMsgMap[r.SSHErrorCodeConst.ETIMEDOUT].message,e=o.SSHErrorMsgMap[r.SSHErrorCodeConst.ETIMEDOUT].detail;break;case r.SSHErrorCodeConst.EHOSTUNREACH:S=o.SSHErrorMsgMap[r.SSHErrorCodeConst.EHOSTUNREACH].message,e=o.SSHErrorMsgMap[r.SSHErrorCodeConst.EHOSTUNREACH].detail;break;case r.SSHErrorCodeConst.EAUTH:S=o.SSHErrorMsgMap[r.SSHErrorCodeConst.EAUTH].message,e=o.SSHErrorMsgMap[r.SSHErrorCodeConst.EAUTH].detail;break;case r.SSHErrorCodeConst.ENOENT:S=o.SSHErrorMsgMap[r.SSHErrorCodeConst.ENOENT].message,e=o.SSHErrorMsgMap[r.SSHErrorCodeConst.ENOENT].detail;break;case r.SSHErrorCodeConst.EACCES:S=o.SSHErrorMsgMap[r.SSHErrorCodeConst.EACCES].message,e=o.SSHErrorMsgMap[r.SSHErrorCodeConst.EACCES].detail;break;case r.SSHErrorCodeConst.NO_SUCH_FILE:S=o.SSHErrorMsgMap[r.SSHErrorCodeConst.NO_SUCH_FILE].message,e=o.SSHErrorMsgMap[r.SSHErrorCodeConst.NO_SUCH_FILE].detail;break;case r.SSHErrorCodeConst.PERMISSION_DENIED:S=o.SSHErrorMsgMap[r.SSHErrorCodeConst.PERMISSION_DENIED].message,e=o.SSHErrorMsgMap[r.SSHErrorCodeConst.PERMISSION_DENIED].detail;break;default:S=o.SSHErrorMsgMap[r.SSHErrorCodeConst.UNKNOWN].message,e=o.SSHErrorMsgMap[r.SSHErrorCodeConst.UNKNOWN].detail+(" "+s.stack||"");break}else(C=s.message)!=null&&C.includes("time out")||(a=s.message)!=null&&a.includes("timed out")?(S=o.SSHErrorMsgMap[r.SSHErrorCodeConst.ETIMEDOUT].message,e=o.SSHErrorMsgMap[r.SSHErrorCodeConst.ETIMEDOUT].detail):(S=o.SSHErrorMsgMap[r.SSHErrorCodeConst.UNKNOWN].message,e=o.SSHErrorMsgMap[r.SSHErrorCodeConst.UNKNOWN].detail+(" "+s.message||JSON.stringify(s)));return{success:!1,server:`${E.host||"localhost"}:${E.port||22}`,message:S,detail:e}};exports.errorHandler=H;