Skip to main content

OpraExceptionFilter

NestJS @Catch() exception filter that intercepts errors thrown during OPRA HTTP request handling and serialises them as OPRA-formatted error responses. Falls back to NestJS's built-in BaseExceptionFilter for requests that have no OPRA context.

import { OpraExceptionFilter } from '@opra/nestjs-http';

Extends: BaseExceptionFilter (@nestjs/core)

OpraHttpModule registers this filter automatically — you do not need to apply it manually.


Behaviour​

When an exception is caught:

  1. Checks whether the request has an opraContext property (set by OpraMiddleware).
  2. If yes — pushes the exception into ctx.errors and calls adapter.sendResponse(ctx), producing a standard OPRA error body with the correct HTTP status code.
  3. If no — delegates to BaseExceptionFilter, preserving standard NestJS error handling for non-OPRA routes.

Manual registration​

If you need to apply the filter globally outside of OpraHttpModule:

import { APP_FILTER } from '@nestjs/core';
import { OpraExceptionFilter } from '@opra/nestjs-http';

// In your module providers:
{
provide: APP_FILTER,
useClass: OpraExceptionFilter,
}