@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
115 lines (114 loc) • 5.08 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ErrorDeserializer = void 0;
const common_1 = require("@nestjs/common");
class ErrorDeserializer {
deserialize(record) {
let error;
switch (record.name) {
default:
error = new Error(record.message);
error.name = record.name;
// Reattach any custom properties
Object.assign(error, record);
break;
case 'Unknown':
return JSON.parse(record.message);
case 'BadGatewayException':
error = new common_1.BadGatewayException();
this.deserializeHttpException(record, error);
break;
case 'BadRequestException':
error = new common_1.BadRequestException();
this.deserializeHttpException(record, error);
break;
case 'ConflictException':
error = new common_1.ConflictException();
this.deserializeHttpException(record, error);
break;
case 'ForbiddenException':
error = new common_1.ForbiddenException();
this.deserializeHttpException(record, error);
break;
case 'GatewayTimeoutException':
error = new common_1.GatewayTimeoutException();
this.deserializeHttpException(record, error);
break;
case 'GoneException':
error = new common_1.GoneException();
this.deserializeHttpException(record, error);
break;
case 'HttpVersionNotSupportedException':
error = new common_1.HttpVersionNotSupportedException();
this.deserializeHttpException(record, error);
break;
case 'ImATeapotException':
error = new common_1.ImATeapotException();
this.deserializeHttpException(record, error);
break;
case 'InternalServerErrorException':
error = new common_1.InternalServerErrorException();
this.deserializeHttpException(record, error);
break;
case 'MethodNotAllowedException':
error = new common_1.MethodNotAllowedException();
this.deserializeHttpException(record, error);
break;
case 'MisdirectedException':
error = new common_1.MisdirectedException();
this.deserializeHttpException(record, error);
break;
case 'NotAcceptableException':
error = new common_1.NotAcceptableException();
this.deserializeHttpException(record, error);
break;
case 'NotFoundException':
error = new common_1.NotFoundException();
this.deserializeHttpException(record, error);
break;
case 'NotImplementedException':
error = new common_1.NotImplementedException();
this.deserializeHttpException(record, error);
break;
case 'PayloadTooLargeException':
error = new common_1.PayloadTooLargeException();
this.deserializeHttpException(record, error);
break;
case 'PreconditionFailedException':
error = new common_1.PreconditionFailedException();
this.deserializeHttpException(record, error);
break;
case 'RequestTimeoutException':
error = new common_1.RequestTimeoutException();
this.deserializeHttpException(record, error);
break;
case 'ServiceUnavailableException':
error = new common_1.ServiceUnavailableException();
this.deserializeHttpException(record, error);
break;
case 'UnauthorizedException':
error = new common_1.UnauthorizedException();
this.deserializeHttpException(record, error);
break;
case 'UnprocessableEntityException':
error = new common_1.UnprocessableEntityException();
this.deserializeHttpException(record, error);
break;
case 'UnsupportedMediaTypeException':
error = new common_1.UnsupportedMediaTypeException();
this.deserializeHttpException(record, error);
break;
}
Reflect.set(error, 'originalStack', error.stack);
Reflect.set(error, 'stack', undefined);
return error;
}
deserializeHttpException(record, error) {
error.name = record.name;
error.message = record.message;
error.cause = record['cause'];
Reflect.set(error, 'response', record['response']);
Reflect.set(error, 'status', record['status']);
}
}
exports.ErrorDeserializer = ErrorDeserializer;