UNPKG

@nestjs/core

Version:

Nest - modern, fast, powerful node.js web framework (@core)

38 lines (37 loc) 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const constants_1 = require("@nestjs/common/constants"); const shared_utils_1 = require("@nestjs/common/utils/shared.utils"); const base_exception_filter_context_1 = require("../exceptions/base-exception-filter-context"); const exceptions_handler_1 = require("../exceptions/exceptions-handler"); const constants_2 = require("../injector/constants"); class RouterExceptionFilters extends base_exception_filter_context_1.BaseExceptionFilterContext { constructor(container, config, applicationRef) { super(container); this.config = config; this.applicationRef = applicationRef; } create(instance, callback, module, contextId = constants_2.STATIC_CONTEXT, inquirerId) { this.moduleContext = module; const exceptionHandler = new exceptions_handler_1.ExceptionsHandler(this.applicationRef); const filters = this.createContext(instance, callback, constants_1.EXCEPTION_FILTERS_METADATA, contextId, inquirerId); if (shared_utils_1.isEmpty(filters)) { return exceptionHandler; } exceptionHandler.setCustomFilters(filters.reverse()); return exceptionHandler; } getGlobalMetadata(contextId = constants_2.STATIC_CONTEXT, inquirerId) { const globalFilters = this.config.getGlobalFilters(); if (contextId === constants_2.STATIC_CONTEXT && !inquirerId) { return globalFilters; } const scopedFilterWrappers = this.config.getGlobalRequestFilters(); const scopedFilters = scopedFilterWrappers .map(wrapper => wrapper.getInstanceByContextId(contextId, inquirerId)) .filter(host => host) .map(host => host.instance); return globalFilters.concat(scopedFilters); } } exports.RouterExceptionFilters = RouterExceptionFilters;