fix: show invalid nickname connection errors

This commit is contained in:
illusia committed 2026-09-13 08:08:40 +08:00
1 parent d13b3207a9
commit ef3e65ea0b
5 files changed
+22 -4

No files matched your search

+6
View File
@@ -1,5 +1,6 @@
export type WebSpeakErrorCode =
| "invalid_target"
| "invalid_nickname"
| "host_not_found"
| "unreachable"
| "connection_refused"
@@ -12,6 +13,7 @@ export type WebSpeakErrorCode =
export type ClientConnectionFailureCode =
| "INVALID_TARGET"
| "INVALID_NICKNAME"
| "HOST_NOT_FOUND"
| "UNREACHABLE"
| "CONNECTION_REFUSED"
@@ -60,6 +62,9 @@ export function normalizeTeamSpeakError(error: unknown): WebSpeakError {
if (/password|authenticate|authentication|not authorized|invalid.*(credential|password)/.test(text)) {
return new WebSpeakError("authentication_failed", "TeamSpeak authentication failed", false, error, diagnostics);
}
if (/invalid parameter size|nickname.{0,20}(length|size)|(?:length|size).{0,20}nickname|id[=: ]1541/.test(text)) {
return new WebSpeakError("invalid_nickname", "TeamSpeak nickname length is invalid", false, error, diagnostics);
}
if (/enotfound|eai_again|host not found|name or service not known|dns/.test(text)) {
return new WebSpeakError("host_not_found", "TeamSpeak server hostname could not be resolved", true, error, diagnostics);
}
@@ -87,6 +92,7 @@ export function clientConnectionFailureCode(error: WebSpeakError, serverPassword
}
const mapping: Record<WebSpeakErrorCode, ClientConnectionFailureCode> = {
invalid_target: "INVALID_TARGET",
invalid_nickname: "INVALID_NICKNAME",
host_not_found: "HOST_NOT_FOUND",
unreachable: "UNREACHABLE",
connection_refused: "CONNECTION_REFUSED",
+2
View File
@@ -5,6 +5,7 @@ import { TSClient } from "./ts-client.js";
import type { TeamSpeakProtocol } from "./teamspeak-adapter.js";
export type ProbeErrorCode =
| "INVALID_NICKNAME"
| "HOST_NOT_FOUND"
| "UNREACHABLE"
| "CONNECTION_REFUSED"
@@ -104,6 +105,7 @@ export function toProbeError(error: unknown, password = ""): TeamSpeakProbeError
}
const mapping: Record<WebSpeakErrorCode, ProbeErrorCode> = {
invalid_target: "INTERNAL_ERROR",
invalid_nickname: "INVALID_NICKNAME",
unreachable: "UNREACHABLE",
host_not_found: "HOST_NOT_FOUND",
connection_refused: "CONNECTION_REFUSED",