Skip to content

[NestJS] SentryGlobalFilter silently drops non-NestJS exceptions that have a status or error property (e.g. AxiosError) #19519

@hartbit

Description

@hartbit

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Which SDK are you using?

@sentry/nestjs

SDK Version

9.4.0

Framework Version

NestJS 11.1.3

Link to Sentry event

No event is created — that's the bug.

SDK Setup

// sentry-instrument.ts (loaded before everything else)
import * as Sentry from '@sentry/nestjs';

Sentry.init({
  dsn: '...',
  environment: 'test',
});
// app.module.ts
import { SentryGlobalFilter, SentryModule } from '@sentry/nestjs/setup';

@Module({
  imports: [SentryModule.forRoot(), /* ... */],
  providers: [
    {
      provide: APP_FILTER,
      useClass: SentryGlobalFilter,
    },
  ],
})
export class AppModule {}

Steps to Reproduce

  1. Register SentryGlobalFilter as a global exception filter
  2. Have a service that makes HTTP calls with Axios (or any library whose errors have a status property)
  3. Let an AxiosError propagate unhandled to the filter (e.g. a 404 from an upstream API)
// some.service.ts
import axios from 'axios';

@Injectable()
export class SomeService {
  async callUpstreamApi() {
    // This throws an AxiosError with { status: 404 } when the resource doesn't exist
    await axios.put('https://some-api.example.com/resource/123', data);
  }
}

Expected Result

The AxiosError should be captured by Sentry since it is not a NestJS HttpException or RpcException — it is a genuine unexpected error from an upstream API call.

Actual Result

The error is silently dropped and never reported to Sentry. It only appears in application logs.

Root Cause

The isExpectedError helper (introduced in #13278) checks whether the exception object has a status or error property:

export function isExpectedError(exception: unknown): boolean {
  if (typeof exception === 'object' && exception !== null) {
    return 'status' in exception || 'error' in exception;
  }
  return false;
}

This condition is very broad — status and error are extremely common property names on error objects. In practice this silently filters out AxiosError, and likely many other error types from database drivers, gRPC clients, or custom error classes that we'd want reported to Sentry.

Metadata

Metadata

Assignees

Labels

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions