Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Update record-audit-log.ts

Kiran Ka613950051c8
diff --git a/apps/web/lib/api/audit-logs/record-audit-log.ts b/apps/web/lib/api/audit-logs/record-audit-log.ts
index c08940c4c7..44545f2816 100644
--- a/apps/web/lib/api/audit-logs/record-audit-log.ts
+++ b/apps/web/lib/api/audit-logs/record-audit-log.ts
@@ -1,4 +1,5 @@
import { tb } from "@/lib/tinybird";
+import { log } from "@dub/utils";
import { ipAddress } from "@vercel/functions";
import { headers } from "next/headers";
import { z } from "zod";
@@ -6,8 +7,6 @@ import { createId } from "../create-id";
import { getIP } from "../utils";
import { auditLogSchemaTB, recordAuditLogInputSchema } from "./schemas";
-const DEBUG_AUDIT_LOGS = false;
-
type AuditLogInput = z.infer<typeof recordAuditLogInputSchema>;
const transformAuditLogTB = (data: AuditLogInput) => {
@@ -45,16 +44,21 @@ export const recordAuditLog = async (data: AuditLogInput | AuditLogInput[]) => {
? data.map(transformAuditLogTB)
: [transformAuditLogTB(data)];
- if (DEBUG_AUDIT_LOGS) {
- console.log(auditLogs);
- }
-
- await recordAuditLogTB(auditLogs).catch((error) => {
- console.error("Failed to record audit log", error, auditLogs);
+ try {
+ await recordAuditLogTB(auditLogs);
+ } catch (error) {
+ console.error(
+ "Failed to record audit log",
+ error,
+ JSON.stringify(auditLogs),
+ );
- // TODO:
- // Send a Slack notification
- });
+ await log({
+ message: "Failed to record audit log. See logs for more details.",
+ type: "errors",
+ mention: true,
+ });
+ }
};
const recordAuditLogTB = tb.buildIngestEndpoint({