feat(alarms): 完成 M06 报警中心与人工处理
落地正式异常创建/合并、三状态人工处置与控制台,关闭 M06 DONE_LOCAL(含 D40 认领文案「处理」)。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
df991417d7
commit
47d3b85a4b
88 files changed
+12658
-30
No files matched your search
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Alarm API failures as fixed copy. The server message is never shown.
|
||||
* Boundary: reason codes and the numeric envelope code only.
|
||||
* Depends on BusinessError from the shared API client.
|
||||
*/
|
||||
|
||||
import { BusinessError } from "@watchman/api";
|
||||
|
||||
type Translate = (key: string, named?: Record<string, unknown>) => string;
|
||||
type Exists = (key: string) => boolean;
|
||||
|
||||
export function describeAlarmError(
|
||||
error: unknown,
|
||||
t: Translate,
|
||||
te: Exists,
|
||||
fallbackKey: string,
|
||||
permissionNode?: string,
|
||||
): string {
|
||||
if (!(error instanceof BusinessError)) {
|
||||
return t(fallbackKey);
|
||||
}
|
||||
if (error.status === 403 || error.code === 42000) {
|
||||
if (permissionNode) {
|
||||
return t("alarm.errors.forbidden", { node: permissionNode });
|
||||
}
|
||||
return t("alarm.errors.forbiddenPlain");
|
||||
}
|
||||
const reason = error.details.reason;
|
||||
if (typeof reason === "string" && te(`alarm.errors.${reason}`)) {
|
||||
return t(`alarm.errors.${reason}`);
|
||||
}
|
||||
if (te(`codes.${error.code}`)) {
|
||||
return `${t(`codes.${error.code}`)} (${error.code})`;
|
||||
}
|
||||
return `${t(fallbackKey)} (${error.code})`;
|
||||
}
|
||||
|
||||
export function isAlarmNotFound(error: unknown): boolean {
|
||||
return error instanceof BusinessError && error.status === 404;
|
||||
}
|
||||
|
||||
export function isAlarmConflict(error: unknown): boolean {
|
||||
return error instanceof BusinessError && error.status === 409;
|
||||
}
|
||||
|
||||
export function isAlarmForbidden(error: unknown): boolean {
|
||||
return error instanceof BusinessError && (error.status === 403 || error.code === 42000);
|
||||
}
|
||||
Reference in new issue
Block a user