Skip to content

setupNestErrorHandler does not work properly within a NestJS + GraphQL application #12128

Closed
@Blargel

Description

@Blargel

Is there an existing issue for this?

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

  1. Clone this repo: https://github.com/Blargel/sentry-nestjs-graphql-test
  2. npm install
  3. Open src/main.ts and change the DSN const to something valid.
  4. npm start
  5. In a web browser, go to http://localhost:3000/
  6. Observe that an error is raised and reported to Sentry correctly. This is a regular HTTP endpoint with an error and works as expected.
  7. In a web browser, go to http://localhost:3000/graphql
  8. 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}.
  9. Execute the query by pressing the play button in the top middle of the GraphQL explorer.
  10. Observe that a strange TypeError is 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)

Metadata

Metadata

Assignees

Labels

Package: nodeIssues related to the Sentry Node SDK

Type

Projects

Status

Waiting for: Product Owner

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions