1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.ExternalExceptionFilterContext = void 0;
|
4 | const constants_1 = require("@nestjs/common/constants");
|
5 | const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
6 | const constants_2 = require("../injector/constants");
|
7 | const base_exception_filter_context_1 = require("./base-exception-filter-context");
|
8 | const external_exceptions_handler_1 = require("./external-exceptions-handler");
|
9 | const iterare_1 = require("iterare");
|
10 | class ExternalExceptionFilterContext extends base_exception_filter_context_1.BaseExceptionFilterContext {
|
11 | constructor(container, config) {
|
12 | super(container);
|
13 | this.config = config;
|
14 | }
|
15 | create(instance, callback, module, contextId = constants_2.STATIC_CONTEXT, inquirerId) {
|
16 | this.moduleContext = module;
|
17 | const exceptionHandler = new external_exceptions_handler_1.ExternalExceptionsHandler();
|
18 | const filters = this.createContext(instance, callback, constants_1.EXCEPTION_FILTERS_METADATA, contextId, inquirerId);
|
19 | if ((0, shared_utils_1.isEmpty)(filters)) {
|
20 | return exceptionHandler;
|
21 | }
|
22 | exceptionHandler.setCustomFilters(filters.reverse());
|
23 | return exceptionHandler;
|
24 | }
|
25 | getGlobalMetadata(contextId = constants_2.STATIC_CONTEXT, inquirerId) {
|
26 | if (!this.config) {
|
27 | return [];
|
28 | }
|
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(contextId, inquirerId))
|
36 | .filter(host => !!host)
|
37 | .map(host => host.instance)
|
38 | .toArray();
|
39 | return globalFilters.concat(scopedFilters);
|
40 | }
|
41 | }
|
42 | exports.ExternalExceptionFilterContext = ExternalExceptionFilterContext;
|