dd4b63a0ee
Add errorReporter (errorToast = toast.error + fire-and-forget POST to /api/error-logs) and wire it into the operational error toasts across chat, threads, tasks, agents, models, files and clipboard. Pure form validation hints stay on toast.error. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { toast } from "sonner";
|
|
|
|
/** Fire-and-forget report of a user-visible error to the per-user error log.
|
|
* Listeners (the notification bell) are only notified once the entry is
|
|
* durably stored, so the badge never counts entries the user cannot see. */
|
|
|
|
const listeners = new Set<() => void>();
|
|
|
|
export function subscribeErrorLogged(listener: () => void): () => void {
|
|
listeners.add(listener);
|
|
return () => {
|
|
listeners.delete(listener);
|
|
};
|
|
}
|
|
|
|
export function reportError(
|
|
source: string,
|
|
message: string,
|
|
details?: string
|
|
): void {
|
|
void fetch("/api/error-logs", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
source,
|
|
message,
|
|
...(details ? { details } : {}),
|
|
}),
|
|
})
|
|
.then((response) => {
|
|
if (!response.ok) return;
|
|
for (const listener of listeners) listener();
|
|
})
|
|
.catch(() => {});
|
|
}
|
|
|
|
/** toast.error + error-log report. Use for operational failures; pure form
|
|
* validation hints should keep using toast.error directly. */
|
|
export function errorToast(
|
|
source: string,
|
|
message: string,
|
|
details?: string
|
|
): void {
|
|
toast.error(message);
|
|
reportError(source, message, details);
|
|
}
|