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