refactor(errors): unify EkbError hierarchy across domains and structured CLI error classification

This commit is contained in:
gitea committed 2026-09-30 00:13:35 +08:00
1 parent 2b220bc5d9
commit c15d622ba2
8 files changed
+89 -40

No files matched your search

+12
View File
@@ -1,3 +1,5 @@
import { EkbError } from "../core/errors.js";
export type CliExitCode = 1 | 2 | 10 | 11 | 12;
export class CliError extends Error {
@@ -35,6 +37,15 @@ export function classifyCliError(error: unknown): {
return { exitCode: error.exitCode, nextAction: error.nextAction };
}
if (error instanceof EkbError) {
if (error.code === "NOT_LOGGED_IN" || error.code === "AUTH_FAILED" || error.status === 401) {
return { exitCode: 11, nextAction: "hose-use auth login" };
}
if (error.code === "VALIDATION_ERROR") {
return { exitCode: 2 };
}
}
const value = error instanceof Error ? error.message : String(error);
const status = responseStatus(error);
if (status === 401 || status === 403 || /(?:^|\s)(?:token|bearer|session) (?:expired|missing|invalid)/i.test(value)) {
@@ -56,3 +67,4 @@ function responseStatus(error: unknown): number | undefined {
const status = (response as { status?: unknown }).status;
return typeof status === "number" ? status : undefined;
}