1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.BaseRpcExceptionFilter = void 0;
|
4 |
|
5 | const common_1 = require("@nestjs/common");
|
6 | const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
7 | const constants_1 = require("@nestjs/core/constants");
|
8 | const rxjs_1 = require("rxjs");
|
9 | const rpc_exception_1 = require("./rpc-exception");
|
10 |
|
11 |
|
12 |
|
13 | class BaseRpcExceptionFilter {
|
14 | catch(exception, host) {
|
15 | const status = 'error';
|
16 | if (!(exception instanceof rpc_exception_1.RpcException)) {
|
17 | return this.handleUnknownError(exception, status);
|
18 | }
|
19 | const res = exception.getError();
|
20 | const message = (0, shared_utils_1.isObject)(res) ? res : { status, message: res };
|
21 | return (0, rxjs_1.throwError)(() => message);
|
22 | }
|
23 | handleUnknownError(exception, status) {
|
24 | const errorMessage = constants_1.MESSAGES.UNKNOWN_EXCEPTION_MESSAGE;
|
25 | const loggerArgs = this.isError(exception)
|
26 | ? [exception.message, exception.stack]
|
27 | : [exception];
|
28 | const logger = BaseRpcExceptionFilter.logger;
|
29 | logger.error.apply(logger, loggerArgs);
|
30 | return (0, rxjs_1.throwError)(() => ({ status, message: errorMessage }));
|
31 | }
|
32 | isError(exception) {
|
33 | return !!((0, shared_utils_1.isObject)(exception) && exception.message);
|
34 | }
|
35 | }
|
36 | exports.BaseRpcExceptionFilter = BaseRpcExceptionFilter;
|
37 | BaseRpcExceptionFilter.logger = new common_1.Logger('RpcExceptionsHandler');
|