chore: migrate frontend assets to OSS and same-origin APIs
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
const ERROR_REPORT_ENDPOINT = "/api/client-errors";
|
||||
const CLIENT_ERROR_REPORTING_ENABLED = import.meta.env.VITE_ENABLE_CLIENT_ERROR_REPORTING === "1";
|
||||
|
||||
interface ErrorReport {
|
||||
message: string;
|
||||
@@ -28,12 +27,16 @@ function getSessionId(): string | undefined {
|
||||
function flush() {
|
||||
if (reportQueue.length === 0) return;
|
||||
const batch = reportQueue.splice(0, 10);
|
||||
const baseUrl = import.meta.env.VITE_API_BASE_URL || "";
|
||||
const url = `${baseUrl}${ERROR_REPORT_ENDPOINT}`;
|
||||
const token = localStorage.getItem("omniai:token") || sessionStorage.getItem("omniai:token") || "";
|
||||
const headers: Record<string, string> = { "Content-Type": "application/json" };
|
||||
if (token) headers["Authorization"] = `Bearer ${token}`;
|
||||
navigator.sendBeacon?.(url, new Blob([JSON.stringify({ errors: batch })], { type: "application/json" }));
|
||||
const payload = new Blob([JSON.stringify({ errors: batch })], { type: "application/json" });
|
||||
if (navigator.sendBeacon?.(ERROR_REPORT_ENDPOINT, payload)) return;
|
||||
|
||||
void fetch(ERROR_REPORT_ENDPOINT, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ errors: batch }),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
credentials: "include",
|
||||
keepalive: true,
|
||||
}).catch(() => {});
|
||||
}
|
||||
|
||||
function scheduleFlush() {
|
||||
@@ -45,8 +48,6 @@ function scheduleFlush() {
|
||||
}
|
||||
|
||||
export function reportError(error: unknown, source: ErrorReport["source"] = "manual") {
|
||||
if (!CLIENT_ERROR_REPORTING_ENABLED) return;
|
||||
|
||||
const err = error instanceof Error ? error : new Error(String(error));
|
||||
const report: ErrorReport = {
|
||||
message: err.message,
|
||||
|
||||
Reference in New Issue
Block a user