2.03 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.ExceptionFiltersContext = void 0;
4const constants_1 = require("@nestjs/common/constants");
5const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
6const base_exception_filter_context_1 = require("@nestjs/core/exceptions/base-exception-filter-context");
7const constants_2 = require("@nestjs/core/injector/constants");
8const iterare_1 = require("iterare");
9const rpc_exceptions_handler_1 = require("../exceptions/rpc-exceptions-handler");
10/**
11 * @publicApi
12 */
13class 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}
42exports.ExceptionFiltersContext = ExceptionFiltersContext;