1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.RpcExceptionsHandler = void 0;
|
4 | const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
5 | const select_exception_filter_metadata_util_1 = require("@nestjs/common/utils/select-exception-filter-metadata.util");
|
6 | const invalid_exception_filter_exception_1 = require("@nestjs/core/errors/exceptions/invalid-exception-filter.exception");
|
7 | const base_rpc_exception_filter_1 = require("./base-rpc-exception-filter");
|
8 |
|
9 |
|
10 |
|
11 | class RpcExceptionsHandler extends base_rpc_exception_filter_1.BaseRpcExceptionFilter {
|
12 | constructor() {
|
13 | super(...arguments);
|
14 | this.filters = [];
|
15 | }
|
16 | handle(exception, host) {
|
17 | const filterResult$ = this.invokeCustomFilters(exception, host);
|
18 | if (filterResult$) {
|
19 | return filterResult$;
|
20 | }
|
21 | return super.catch(exception, host);
|
22 | }
|
23 | setCustomFilters(filters) {
|
24 | if (!Array.isArray(filters)) {
|
25 | throw new invalid_exception_filter_exception_1.InvalidExceptionFilterException();
|
26 | }
|
27 | this.filters = filters;
|
28 | }
|
29 | invokeCustomFilters(exception, host) {
|
30 | if ((0, shared_utils_1.isEmpty)(this.filters)) {
|
31 | return null;
|
32 | }
|
33 | const filter = (0, select_exception_filter_metadata_util_1.selectExceptionFilterMetadata)(this.filters, exception);
|
34 | return filter ? filter.func(exception, host) : null;
|
35 | }
|
36 | }
|
37 | exports.RpcExceptionsHandler = RpcExceptionsHandler;
|