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