UNPKG

@nestjs/microservices

Version:

Nest - modern, fast, powerful node.js web framework (@microservices)

30 lines (29 loc) • 730 B
import { isObject, isString } from '@nestjs/common/internal'; /** * @publicApi */ export class RpcException extends Error { error; constructor(error) { super(); this.error = error; this.initMessage(); } initMessage() { if (isString(this.error)) { this.message = this.error; } else if (isObject(this.error) && isString(this.error.message)) { this.message = this.error.message; } else if (this.constructor) { this.message = this.constructor.name.match(/[A-Z][a-z]+|[0-9]+/g)?.join(' ') ?? 'Error'; } } getError() { return this.error; } }