fix: keep the errors endpoint out of the Bulwark Lite bundle

This commit is contained in:
Linus Rath
2026-11-01 04:35:04 +01:00
parent e7f3b21c06
commit 79f73c5c84
2 changed files with 41 additions and 1 deletions
@@ -0,0 +1,37 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
vi.mock('@/lib/lite', async (importOriginal) => ({
...(await importOriginal<typeof import('@/lib/lite')>()),
IS_LITE: true,
}));
import { captureException, configureErrorReporting, resetErrorReportingForTests } from '../client';
const DSN = 'https://6f0b9c79ed3a4315b76595bc2536ac40@bugsink.example.org/3';
let fetchSpy: ReturnType<typeof vi.fn>;
beforeEach(() => {
resetErrorReportingForTests();
sessionStorage.clear();
fetchSpy = vi.fn().mockResolvedValue(new Response(null, { status: 200 }));
vi.stubGlobal('fetch', fetchSpy);
});
afterEach(() => {
vi.unstubAllGlobals();
});
// Bulwark Lite has no server, so it never posts to /api/errors, whatever
// the settings say; reports go to the DSN only.
describe('error reporting in Lite', () => {
it('sends to the DSN and never to /api/errors', () => {
configureErrorReporting({ dsn: DSN, sampleRate: 1, environment: 'lite', collect: true });
const error = new TypeError('boom');
error.stack = 'TypeError: boom\n at a (https://lite.example.org/_next/static/chunks/1.js:2:30)';
captureException(error);
const urls = fetchSpy.mock.calls.map(([url]) => String(url));
expect(urls).toHaveLength(1);
expect(urls[0]).toContain('/api/3/envelope/');
expect(urls.some((url) => url.includes('/api/errors'))).toBe(false);
});
});
+4 -1
View File
@@ -1,4 +1,5 @@
import { apiFetch, getPathPrefix } from '@/lib/browser-navigation';
import { IS_LITE } from '@/lib/lite';
import { scrubRoutePath } from '@/lib/route-groups';
import { debugIdsByPath } from './debug-ids';
import {
@@ -200,7 +201,9 @@ function deliver(report: ErrorReport): void {
mode: 'cors',
});
}
if (settings.collect) {
// Lite has no server: the bundler drops this branch, and the endpoint
// with it (scripts/lite/verify.mjs fails on undocumented /api strings).
if (!IS_LITE && settings.collect) {
send('/api/errors', JSON.stringify({
name: report.name,
message: report.message,