|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { waitForError } from '@sentry-internal/test-utils'; |
| 3 | + |
| 4 | +test('captures error thrown in route handler', async ({ baseURL }) => { |
| 5 | + const errorWaiter = waitForError('hono-4-cf', event => { |
| 6 | + return event.exception?.values?.[0]?.value === 'This is a test error for Sentry!'; |
| 7 | + }); |
| 8 | + |
| 9 | + const response = await fetch(`${baseURL}/error/test-cause`); |
| 10 | + expect(response.status).toBe(500); |
| 11 | + |
| 12 | + const event = await errorWaiter; |
| 13 | + expect(event.exception?.values?.[0]?.value).toBe('This is a test error for Sentry!'); |
| 14 | +}); |
| 15 | + |
| 16 | +test('captures HTTPException with 502 status', async ({ baseURL }) => { |
| 17 | + const errorWaiter = waitForError('hono-4-cf', event => { |
| 18 | + return event.exception?.values?.[0]?.value === 'HTTPException 502'; |
| 19 | + }); |
| 20 | + |
| 21 | + const response = await fetch(`${baseURL}/http-exception/502`); |
| 22 | + expect(response.status).toBe(502); |
| 23 | + |
| 24 | + const event = await errorWaiter; |
| 25 | + expect(event.exception?.values?.[0]?.value).toBe('HTTPException 502'); |
| 26 | +}); |
| 27 | + |
| 28 | +// TODO: 401 and 404 HTTPExceptions should not be captured by Sentry by default, |
| 29 | +// but currently they are. Fix the filtering and update these tests accordingly. |
| 30 | +test('captures HTTPException with 401 status', async ({ baseURL }) => { |
| 31 | + const errorWaiter = waitForError('hono-4-cf', event => { |
| 32 | + return event.exception?.values?.[0]?.value === 'HTTPException 401'; |
| 33 | + }); |
| 34 | + |
| 35 | + const response = await fetch(`${baseURL}/http-exception/401`); |
| 36 | + expect(response.status).toBe(401); |
| 37 | + |
| 38 | + const event = await errorWaiter; |
| 39 | + expect(event.exception?.values?.[0]?.value).toBe('HTTPException 401'); |
| 40 | +}); |
| 41 | + |
| 42 | +test('captures HTTPException with 404 status', async ({ baseURL }) => { |
| 43 | + const errorWaiter = waitForError('hono-4-cf', event => { |
| 44 | + return event.exception?.values?.[0]?.value === 'HTTPException 404'; |
| 45 | + }); |
| 46 | + |
| 47 | + const response = await fetch(`${baseURL}/http-exception/404`); |
| 48 | + expect(response.status).toBe(404); |
| 49 | + |
| 50 | + const event = await errorWaiter; |
| 51 | + expect(event.exception?.values?.[0]?.value).toBe('HTTPException 404'); |
| 52 | +}); |
0 commit comments