Hello! I want to serialize errors from my TCP service. I've setup a custom proxy. When I use it to connect to my microservice, I get a ECONNREFUSED error. When I don't, everything works. Is there a special way I should create my microservice so that the client can connect?
I've simplified the code of course, only adding the CLIENT app's module that connects to the service, and how I create the microservice in the SERVICE app. Thanks!
ERROR PROXY
export class TcpErrorHandlingProxy extends ClientTCP {
serializeError(err: Error): RpcException {
return new RpcException(err);
}
}
CLIENT APP
@Module({
imports: [ConfigModule.forRoot({ load: [serviceConfig] })],
providers: [
{
provide: SERVICE_PACKAGE_TOKEN,
useFactory: async (configService: ConfigService): Promise<ClientProxy> => {
const { host, port } = configService.get<serviceConfig>('service')!;
const microserviceOptions: TcpClientOptions = { transport: Transport.TCP, options: { host, port } };
return ClientProxyFactory.create(microserviceOptions); // <= THIS WORKS
//--------------------//
return ClientProxyFactory.create({ customClass: TcpErrorHandlingProxy, options: microserviceOptions }); //<= THIS DOES NOT WORK: ECONNREFUSED on connection
},
inject: [ConfigService],
},
],
exports: [SERVICE_PACKAGE_TOKEN],
})
export default class MicroserviceClientModule {}
SERVICE APP
const app = await NestFactory.createMicroservice<MicroserviceOptions>(AppModule, {
transport: Transport.TCP,
options: {
host,
port,
retryAttempts: 5,
retryDelay: 10,
},
});