fix: harden analytics writes and hide internal server errors from client

This commit is contained in:
Francis Cao committed 2026-06-22 22:07:07 -07:00
1 parent 770b4d59d2
commit 129681ebd7
15 files changed
+217 -128

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
import { describe, expect, test, vi } from 'vitest';
import { serverError } from './response';
describe('serverError', () => {
test('does not expose internal error details in the response body', async () => {
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
const response = serverError(new Error('database exploded'));
expect(await response.json()).toEqual({
error: {
message: 'Server error',
code: 'server-error',
status: 500,
},
});
logSpy.mockRestore();
});
test('allows intentional server error messages', async () => {
const response = serverError('Redis is disabled');
expect(await response.json()).toEqual({
error: {
message: 'Redis is disabled',
code: 'server-error',
status: 500,
},
});
});
});