@nestjs/microservices
Version:
Microservices for NestJS: message and event handlers over Kafka, RabbitMQ, NATS, Redis, MQTT, gRPC or TCP.
30 lines (29 loc) • 730 B
JavaScript
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;
}
}