@rxap/nest-rabbitmq
Version:
This package provides a NestJS module for integrating with RabbitMQ using exchanges. It offers a client and server implementation for message queuing and supports features like health checks and error serialization. It simplifies the process of setting up
40 lines (39 loc) • 1.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ErrorSerializer = void 0;
const common_1 = require("@nestjs/common");
class ErrorSerializer {
serialize(error) {
if (!(error instanceof Error)) {
return {
message: this.stringifyCircular(error),
name: 'Unknown',
};
}
const serializedError = {
message: error.message,
stack: error.stack,
name: error.name,
};
if (error instanceof common_1.HttpException) {
serializedError['response'] = error.getResponse();
serializedError['status'] = error.getStatus();
serializedError['cause'] = error.cause;
}
return serializedError;
}
stringifyCircular(obj) {
const seenObjects = new Set();
return JSON.stringify(obj, (key, value) => {
if (typeof value === 'object' && value !== null) {
if (seenObjects.has(value)) {
// Detected a circular reference, replace it with a custom string or value
return '[Circular]';
}
seenObjects.add(value);
}
return value;
});
}
}
exports.ErrorSerializer = ErrorSerializer;