diff --git a/lib/error-reporting/__tests__/client-lite.test.ts b/lib/error-reporting/__tests__/client-lite.test.ts new file mode 100644 index 000000000..3c6064839 --- /dev/null +++ b/lib/error-reporting/__tests__/client-lite.test.ts @@ -0,0 +1,37 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; + +vi.mock('@/lib/lite', async (importOriginal) => ({ + ...(await importOriginal()), + IS_LITE: true, +})); + +import { captureException, configureErrorReporting, resetErrorReportingForTests } from '../client'; + +const DSN = 'https://6f0b9c79ed3a4315b76595bc2536ac40@bugsink.example.org/3'; +let fetchSpy: ReturnType; + +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); + }); +}); diff --git a/lib/error-reporting/client.ts b/lib/error-reporting/client.ts index 57f27ca8c..712a21f14 100644 --- a/lib/error-reporting/client.ts +++ b/lib/error-reporting/client.ts @@ -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,