Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
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,
},
});
});
});