#286: request() now throws C2ApiError — message is FastAPI's `detail` or a plain sentence for the status (401/403/404/429/5xx), with toString() so the many String(e) call sites read cleanly. status/body stay on the error; the Discord parsers rebuild the legacy "C2 API error N: body" text via legacyErrorText(), so their invite/code parsing is unchanged. #284: Resolve, Regenerate summary, alert-rule toggle/delete/load, Acknowledge, trip deletes, system delete and Restart OP25 now surface failures (ErrorBanner where the page has one, alert() where the page already uses it). Rules tab no longer says "No alert rules configured" when the load failed. Confirms added for Resolve (no reopen path exists), rule delete and trip delete. Reopen deliberately not built — manual resolve doesn't set resolved_at, so reopening is a lifecycle change. Frontend unverified: no Node on the authoring box (#207). Closes #286 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6d667e81c9
commit
f16f0a9f93
@@ -5,6 +5,8 @@ import { useAuth } from "@/components/AuthProvider";
|
||||
import { useAlerts } from "@/lib/useAlerts";
|
||||
import { MachineOutputNotice } from "@/components/ui/MachineOutputNotice";
|
||||
import { c2api } from "@/lib/c2api";
|
||||
import { errorMessage } from "@/lib/c2error";
|
||||
import { ErrorBanner } from "@/components/ui/EmptyState";
|
||||
import type { AlertRule } from "@/lib/types";
|
||||
|
||||
function fmtTime(iso: string) {
|
||||
@@ -20,6 +22,10 @@ function RulesTab({ isAdmin }: { isAdmin: boolean }) {
|
||||
const [webhook, setWebhook] = useState("");
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
// Load and toggle/delete failures (server-26#284) — separate from the create
|
||||
// form's own `error`, and it keeps the list from claiming "no rules" when
|
||||
// the fetch actually failed.
|
||||
const [listError, setListError] = useState<string | null>(null);
|
||||
|
||||
async function load() {
|
||||
if (loaded) return;
|
||||
@@ -27,8 +33,9 @@ function RulesTab({ isAdmin }: { isAdmin: boolean }) {
|
||||
const data = await c2api.getAlertRules() as AlertRule[];
|
||||
setRules(data);
|
||||
setLoaded(true);
|
||||
setListError(null);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
setListError(`Couldn't load alert rules: ${errorMessage(e)}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,8 +57,8 @@ function RulesTab({ isAdmin }: { isAdmin: boolean }) {
|
||||
const created = await c2api.createAlertRule(body) as AlertRule;
|
||||
setRules((prev) => [created, ...prev]);
|
||||
setName(""); setKeywords(""); setTgIds(""); setWebhook("");
|
||||
} catch {
|
||||
setError("Failed to create rule.");
|
||||
} catch (e) {
|
||||
setError(`Failed to create rule: ${errorMessage(e)}`);
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
@@ -61,14 +68,17 @@ function RulesTab({ isAdmin }: { isAdmin: boolean }) {
|
||||
try {
|
||||
await c2api.updateAlertRule(rule.rule_id, { enabled: !rule.enabled });
|
||||
setRules((prev) => prev.map((r) => r.rule_id === rule.rule_id ? { ...r, enabled: !r.enabled } : r));
|
||||
} catch (e) { console.error(e); }
|
||||
setListError(null);
|
||||
} catch (e) { setListError(`Couldn't update "${rule.name}": ${errorMessage(e)}`); }
|
||||
}
|
||||
|
||||
async function handleDelete(id: string) {
|
||||
if (!window.confirm("Delete this alert rule?")) return;
|
||||
try {
|
||||
await c2api.deleteAlertRule(id);
|
||||
setRules((prev) => prev.filter((r) => r.rule_id !== id));
|
||||
} catch (e) { console.error(e); }
|
||||
setListError(null);
|
||||
} catch (e) { setListError(`Couldn't delete the rule: ${errorMessage(e)}`); }
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -120,8 +130,12 @@ function RulesTab({ isAdmin }: { isAdmin: boolean }) {
|
||||
</form>
|
||||
)}
|
||||
|
||||
{listError && <ErrorBanner message={listError} />}
|
||||
|
||||
<div className="bg-surface border border-line rounded-xl overflow-hidden">
|
||||
{rules.length === 0 ? (
|
||||
{!loaded ? (
|
||||
<p className="text-ink-muted text-sm font-mono p-4">{listError ? "Rules unavailable." : "Loading…"}</p>
|
||||
) : rules.length === 0 ? (
|
||||
<p className="text-ink-muted text-sm font-mono p-4">No alert rules configured.</p>
|
||||
) : (
|
||||
<table className="w-full text-left">
|
||||
@@ -188,11 +202,13 @@ export default function AlertsPage() {
|
||||
const { isAdmin } = useAuth();
|
||||
const { alerts, loading, error } = useAlerts();
|
||||
const [tab, setTab] = useState<"events" | "rules">("events");
|
||||
const [ackError, setAckError] = useState<string | null>(null);
|
||||
|
||||
async function handleAcknowledge(id: string) {
|
||||
setAckError(null);
|
||||
try {
|
||||
await c2api.acknowledgeAlert(id);
|
||||
} catch (e) { console.error(e); }
|
||||
} catch (e) { setAckError(`Couldn't acknowledge: ${errorMessage(e)}`); }
|
||||
}
|
||||
|
||||
const unacked = alerts.filter((a) => !a.acknowledged);
|
||||
@@ -223,6 +239,8 @@ export default function AlertsPage() {
|
||||
))}
|
||||
</div>
|
||||
|
||||
{tab === "events" && ackError && <ErrorBanner message={ackError} />}
|
||||
|
||||
{tab === "events" && (
|
||||
loading ? (
|
||||
<p className="text-ink-muted text-sm font-mono">Loading…</p>
|
||||
|
||||
Reference in New Issue
Block a user