Repository navigation
Closed
Closed
Copy link
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/node
SDK Version
8.2.1
Framework Version
@nestjs/core@10.3.8, @nestjs/graphql@12.1.1
Link to Sentry event
No response
SDK Setup
Sentry.init({
dsn: [redacted],
integrations: [nodeProfilingIntegration()],
tracesSampleRate: 1.0,
profilesSampleRate: 1.0,
})
async function bootstrap(): Promise<void> {
const app = await NestFactory.create(AppModule)
Sentry.setupNestErrorHandler(
app,
new BaseExceptionFilter(app.getHttpAdapter()),
)
await app.listen(config.port)
}Steps to Reproduce
- Clone this repo: https://github.com/Blargel/sentry-nestjs-graphql-test
npm install- Open
src/main.tsand change the DSN const to something valid. npm start- In a web browser, go to http://localhost:3000/
- Observe that an error is raised and reported to Sentry correctly. This is a regular HTTP endpoint with an error and works as expected.
- In a web browser, go to http://localhost:3000/graphql
- This will open a GraphQL explorer. I believe it defaults to the correct query for testing but if not, the correct test query is
query {hello}. - Execute the query by pressing the play button in the top middle of the GraphQL explorer.
- Observe that a strange
TypeErroris raised and the original error is not sent to Sentry correctly.
Expected Result
The GraphQL error should also be reported to Sentry without raising the strange TypeError.
Actual Result
No error reported in Sentry and the following error is thrown:
TypeError: response.status is not a function
at ExpressAdapter.reply (~/platform-api/node_modules/@nestjs/platform-express/adapters/express-adapter.js:28:22)
at BaseExceptionFilter.handleUnknownError (~/platform-api/node_modules/@nestjs/core/exceptions/base-exception-filter.js:46:28)
at BaseExceptionFilter.catch (~/platform-api/node_modules/@nestjs/core/exceptions/base-exception-filter.js:17:25)
at Proxy.<anonymous> (~/platform-api/node_modules/@sentry/src/integrations/tracing/nest.ts:80:51)
at ExternalExceptionsHandler.invokeCustomFilters (~/platform-api/node_modules/@nestjs/core/exceptions/external-exceptions-handler.js:31:32)
at ExternalExceptionsHandler.next (~/platform-api/node_modules/@nestjs/core/exceptions/external-exceptions-handler.js:14:29)
at ~/platform-api/node_modules/@nestjs/core/helpers/external-proxy.js:14:42
at processTicksAndRejections (node:internal/process/task_queues:95:5)
Reacted by tomukasas and Robin van Wijngaarden
Metadata
Metadata
Assignees
Labels
No labels
Projects
- StatusShow more project fieldsWaiting for: Product Owner
Activity
onurtemizkan commentedon May 21, 2024
Thanks for reporting this @Blargel!
It looks like GraphQL does not work well with
BaseExceptionFilter. (Ref: nestjs/nest#5958 (comment))I have tried to update your setup as,
And it seemed to work.
Could you check if that resolves the issue?
If so we may need to add a note in the docs about this.
Blargel commentedon May 21, 2024
Hmmmm, that works in the test repo I put in my bug report, but it's not working on my actual application. The same TypeError as before is still being thrown. Let me get back to you on this when I figure out what's different.
Blargel commentedon May 21, 2024
Oops, nevermind it works. Maybe something weird got cached. Anyways, that does fix my issue then. Thanks! Should I leave this open to track documentation updates?
mydea commentedon May 22, 2024
Great that we found a solution - I'll close the issue, users can (hopefully) still find it if they search! 🙏
GustavoContreiras commentedon May 23, 2024
It stopped throwring the
response.statuserror but now I can't access the GraphQL Playground...If I comment
Sentry.setupNestErrorHandler(app, new ExternalExceptionFilter())I can access again.martinvysnovsky commentedon May 24, 2024
I have solved the issue by creating custom exception filter:
Then you can use this filter when initializing Sentry: