refactor(server): add getErrorMessage helper and fix error-related type-aware lint errors (#704)

* refactor(server): add getErrorMessage helper and fix error-related type-aware lint errors in session.ts

* fix build: correct parseClientCapabilities type handling
This commit is contained in:
Mohamed Boudra
2026-05-05 19:57:35 +07:00
parent d359bffed5
commit 8b54d27cbc
2 changed files with 64 additions and 43 deletions
+27
View File
@@ -0,0 +1,27 @@
/**
* Extracts a human-readable error message from an unknown error value.
* Handles Error instances, string errors, and other types safely.
*/
export function getErrorMessage(error: unknown): string {
if (error instanceof Error) {
return error.message;
}
if (typeof error === "string") {
return error;
}
return String(error);
}
/**
* Extracts an error message from an unknown error value, with a fallback
* for when no message can be extracted.
*/
export function getErrorMessageOr(error: unknown, fallback: string): string {
if (error instanceof Error) {
return error.message;
}
if (typeof error === "string" && error.length > 0) {
return error;
}
return fallback;
}