-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nuxt): Set transaction name for server error (#13292)
Setting the transaction name to display the API route where the error happened: ![image](https://github.com/user-attachments/assets/5954fc45-e710-44ab-b29a-f90e6bd480a4)
- Loading branch information
Showing
9 changed files
with
91 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
dev-packages/e2e-tests/test-applications/nuxt-3/pages/fetch-server-error.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<template> | ||
<div> | ||
<button @click="fetchData">Fetch Server Data</button> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
const fetchData = async () => { | ||
await useFetch('/api/server-error'); | ||
} | ||
</script> |
11 changes: 11 additions & 0 deletions
11
dev-packages/e2e-tests/test-applications/nuxt-3/pages/test-param/[param].vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,15 @@ | ||
<template> | ||
<p>{{ $route.params.param }} - {{ $route.params.param }}</p> | ||
|
||
<ErrorButton errorText="Error thrown from Param Route Button" /> | ||
<button @click="fetchData">Fetch Server Data</button> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
const route = useRoute(); | ||
const param = route.params.param; | ||
const fetchData = async () => { | ||
await useFetch(`/api/param-error/${param}`); | ||
} | ||
</script> |
3 changes: 3 additions & 0 deletions
3
dev-packages/e2e-tests/test-applications/nuxt-3/server/api/param-error/[param].ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default defineEventHandler(_e => { | ||
throw new Error('Nuxt 3 Param Server error'); | ||
}); |
3 changes: 3 additions & 0 deletions
3
dev-packages/e2e-tests/test-applications/nuxt-3/server/api/server-error.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default defineEventHandler(event => { | ||
throw new Error('Nuxt 3 Server error'); | ||
}); |
5 changes: 5 additions & 0 deletions
5
dev-packages/e2e-tests/test-applications/nuxt-3/server/api/test-param/[param].ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default defineEventHandler(event => { | ||
const param = getRouterParam(event, 'param'); | ||
|
||
return `Param: ${param}!`; | ||
}); |
3 changes: 3 additions & 0 deletions
3
dev-packages/e2e-tests/test-applications/nuxt-3/server/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "../.nuxt/tsconfig.server.json" | ||
} |
40 changes: 40 additions & 0 deletions
40
dev-packages/e2e-tests/test-applications/nuxt-3/tests/errors.server.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import { waitForError } from '@sentry-internal/test-utils'; | ||
|
||
test.describe('server-side errors', async () => { | ||
test('captures api fetch error (fetched on click)', async ({ page }) => { | ||
const errorPromise = waitForError('nuxt-3', async errorEvent => { | ||
return errorEvent?.exception?.values?.[0]?.value === 'Nuxt 3 Server error'; | ||
}); | ||
|
||
await page.goto(`/fetch-server-error`); | ||
await page.getByText('Fetch Server Data').click(); | ||
|
||
const error = await errorPromise; | ||
|
||
expect(error.transaction).toEqual('GET /api/server-error'); | ||
|
||
const exception = error.exception.values[0]; | ||
expect(exception.type).toEqual('Error'); | ||
expect(exception.value).toEqual('Nuxt 3 Server error'); | ||
expect(exception.mechanism.handled).toBe(false); | ||
}); | ||
|
||
test('captures api fetch error (fetched on click) with parametrized route', async ({ page }) => { | ||
const errorPromise = waitForError('nuxt-3', async errorEvent => { | ||
return errorEvent?.exception?.values?.[0]?.value === 'Nuxt 3 Param Server error'; | ||
}); | ||
|
||
await page.goto(`/test-param/1234`); | ||
await page.getByText('Fetch Server Data').click(); | ||
|
||
const error = await errorPromise; | ||
|
||
expect(error.transaction).toEqual('GET /api/param-error/1234'); | ||
|
||
const exception = error.exception.values[0]; | ||
expect(exception.type).toEqual('Error'); | ||
expect(exception.value).toEqual('Nuxt 3 Param Server error'); | ||
expect(exception.mechanism.handled).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters