1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const constants_1 = require("@nestjs/common/constants");
|
4 | const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
5 | const base_exception_filter_context_1 = require("../exceptions/base-exception-filter-context");
|
6 | const exceptions_handler_1 = require("../exceptions/exceptions-handler");
|
7 | const constants_2 = require("../injector/constants");
|
8 | class RouterExceptionFilters extends base_exception_filter_context_1.BaseExceptionFilterContext {
|
9 | constructor(container, config, applicationRef) {
|
10 | super(container);
|
11 | this.config = config;
|
12 | this.applicationRef = applicationRef;
|
13 | }
|
14 | create(instance, callback, module, contextId = constants_2.STATIC_CONTEXT, inquirerId) {
|
15 | this.moduleContext = module;
|
16 | const exceptionHandler = new exceptions_handler_1.ExceptionsHandler(this.applicationRef);
|
17 | const filters = this.createContext(instance, callback, constants_1.EXCEPTION_FILTERS_METADATA, contextId, inquirerId);
|
18 | if (shared_utils_1.isEmpty(filters)) {
|
19 | return exceptionHandler;
|
20 | }
|
21 | exceptionHandler.setCustomFilters(filters.reverse());
|
22 | return exceptionHandler;
|
23 | }
|
24 | getGlobalMetadata(contextId = constants_2.STATIC_CONTEXT, inquirerId) {
|
25 | const globalFilters = this.config.getGlobalFilters();
|
26 | if (contextId === constants_2.STATIC_CONTEXT && !inquirerId) {
|
27 | return globalFilters;
|
28 | }
|
29 | const scopedFilterWrappers = this.config.getGlobalRequestFilters();
|
30 | const scopedFilters = scopedFilterWrappers
|
31 | .map(wrapper => wrapper.getInstanceByContextId(contextId, inquirerId))
|
32 | .filter(host => host)
|
33 | .map(host => host.instance);
|
34 | return globalFilters.concat(scopedFilters);
|
35 | }
|
36 | }
|
37 | exports.RouterExceptionFilters = RouterExceptionFilters;
|