Skip to content

Commit abf7f9f

Browse files
committed
feat(feedback-api): server-side PostHog capture on E_CRYPTO and E_INSERT errors
1 parent bed64f0 commit abf7f9f

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

  • packages/app/src/app/api/v1/feedback

packages/app/src/app/api/v1/feedback/route.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { utf8ToBytes } from '@noble/ciphers/utils.js';
55
import { getWriteDb } from '@semianalysisai/inferencex-db/connection';
66
import { type Cipher, createCipher, loadKey } from '@semianalysisai/inferencex-db/lib/encryption';
77

8+
import { trackServer } from '@/lib/analytics-server';
89
import { parseFeedbackBody } from './parse';
910

1011
const aadFor = (column: string) => utf8ToBytes(`user_feedback:${column}`);
@@ -55,13 +56,20 @@ export async function POST(request: Request) {
5556
return new NextResponse(null, { status: 204 });
5657
}
5758

59+
const pagePath = body.pagePath ?? null;
5860
let cipher: Cipher;
5961
let sql: ReturnType<typeof getWriteDb>;
6062
try {
6163
cipher = createCipher(loadKey('FEEDBACK_SECRET'));
6264
sql = getWriteDb();
6365
} catch (error) {
6466
console.error('feedback: misconfigured', error);
67+
trackServer('feedback_submission_failed', {
68+
error_code: 'E_CRYPTO',
69+
error_name: error instanceof Error ? error.name : 'Unknown',
70+
error_message: (error instanceof Error ? error.message : String(error)).slice(0, 500),
71+
page_path: pagePath,
72+
});
6573
return serverError('E_CRYPTO');
6674
}
6775

@@ -94,6 +102,12 @@ export async function POST(request: Request) {
94102
`;
95103
} catch (error) {
96104
console.error('feedback: insert failed', error);
105+
trackServer('feedback_submission_failed', {
106+
error_code: 'E_INSERT',
107+
error_name: error instanceof Error ? error.name : 'Unknown',
108+
error_message: (error instanceof Error ? error.message : String(error)).slice(0, 500),
109+
page_path: pagePath,
110+
});
97111
return serverError('E_INSERT');
98112
}
99113

0 commit comments

Comments
 (0)