Skip to content

Commit

Permalink
fix(nuxt): Ignore 300-400 status codes on app errors in Nuxt (#15473)
Browse files Browse the repository at this point in the history
Before submitting a pull request, please take a look at our

[Contributing](https://github.com/getsentry/sentry-javascript/blob/master/CONTRIBUTING.md)
guidelines and verify:

- [ ] If you've added code that should be tested, please add tests.
- [ ] Ensure your code lints and the test suite passes (`yarn lint`) &
(`yarn test`).

### Description

I noticed that Nuxt 300-400 status codes from the app are being reported
to Sentry unnecessarily. There appears to be a guard against doing this
on the server side errors but client side errors like 404 or 401s are
being reported to Sentry.

I have simply added the same guard on the client side error reporter for
the Nuxt integration of Sentry.
  • Loading branch information
GerryWilko authored Feb 26, 2025
1 parent 0867a99 commit 2140b53
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/nuxt/src/runtime/plugins/sentry.client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GLOBAL_OBJ, getClient } from '@sentry/core';
import { browserTracingIntegration, vueIntegration } from '@sentry/vue';
import { defineNuxtPlugin } from 'nuxt/app';
import { defineNuxtPlugin, isNuxtError } from 'nuxt/app';
import type { GlobalObjWithIntegrationOptions } from '../../client/vueIntegration';
import { reportNuxtError } from '../utils';

Expand Down Expand Up @@ -66,6 +66,12 @@ export default defineNuxtPlugin({
});

nuxtApp.hook('app:error', error => {
if (isNuxtError(error)) {
// Do not report if status code is 3xx or 4xx
if (error.statusCode >= 300 && error.statusCode < 500) {
return;
}
}
reportNuxtError({ error });
});

Expand Down

0 comments on commit 2140b53

Please sign in to comment.