UNPKG

910 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.RpcException = void 0;
4const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
5/**
6 * @publicApi
7 */
8class RpcException extends Error {
9 constructor(error) {
10 super();
11 this.error = error;
12 this.initMessage();
13 }
14 initMessage() {
15 if ((0, shared_utils_1.isString)(this.error)) {
16 this.message = this.error;
17 }
18 else if ((0, shared_utils_1.isObject)(this.error) &&
19 (0, shared_utils_1.isString)(this.error.message)) {
20 this.message = this.error.message;
21 }
22 else if (this.constructor) {
23 this.message = this.constructor.name
24 .match(/[A-Z][a-z]+|[0-9]+/g)
25 .join(' ');
26 }
27 }
28 getError() {
29 return this.error;
30 }
31}
32exports.RpcException = RpcException;