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:
- Checks whether the request has an
opraContextproperty (set byOpraMiddleware). - If yes — pushes the exception into
ctx.errorsand callsadapter.sendResponse(ctx), producing a standard OPRA error body with the correct HTTP status code. - 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,
}