UNPKG

@nestjs/core

Version:

The core of NestJS, a TypeScript framework for Node.js backends: modules, dependency injection and the request pipeline, on Express, Fastify or node:http.

29 lines (28 loc) • 1.17 kB
import { InvalidExceptionFilterException } from '../errors/exceptions/invalid-exception-filter.exception.js'; import { ExternalExceptionFilter } from './external-exception-filter.js'; import { selectExceptionFilterMetadata, isEmptyArray, isUndefined, } from '@nestjs/common/internal'; export class ExternalExceptionsHandler extends ExternalExceptionFilter { filters = []; next(exception, host) { const result = this.invokeCustomFilters(exception, host); // `undefined` stands for "not handled": no filter caught the exception, // or the one that did returned nothing if (!isUndefined(result)) { return result; } return super.catch(exception, host); } setCustomFilters(filters) { if (!Array.isArray(filters)) { throw new InvalidExceptionFilterException(); } this.filters = filters; } invokeCustomFilters(exception, host) { if (isEmptyArray(this.filters)) { return; } const filter = selectExceptionFilterMetadata(this.filters, exception); return filter ? filter.func(exception, host) : undefined; } }