Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.nc.requestOne(this.subRequests, Buffer.from(sr.serializeBinary()), this.options.connectTimeout, (msg) => {
if (msg instanceof nats.NatsError) {
if (msg.code === nats.REQ_TIMEOUT) {
const err = new nats.NatsError(SUB_REQ_TIMEOUT, SUB_REQ_TIMEOUT, msg);
retVal.emit('timeout', err);
} else {
retVal.emit('error', msg);
}
return;
}
//noinspection JSUnresolvedVariable
const r = proto.pb.SubscriptionResponse.deserializeBinary(Buffer.from(msg, 'binary'));
const err = r.getError();
if (err && err.length !== 0) {
retVal.emit('error', new Error(err));
this.nc.unsubscribe(retVal.inboxSub);
retVal.emit('unsubscribed');
return;
}
retVal.ackInbox = r.getAckInbox();
sc.nc.requestOne(reqSubject, Buffer.from(ur.serializeBinary()), sc.options.connectTimeout, (msg) => {
let err;
if (msg instanceof nats.NatsError) {
const type = doClose ? CLOSE_REQ_TIMEOUT : UNSUB_REQ_TIMEOUT;
err = new nats.NatsError(type, type, msg);
if (msg.code === nats.REQ_TIMEOUT) {
this.emit('timeout', err);
} else {
this.emit('error', err);
}
return;
}
//noinspection JSUnresolvedVariable
const r = proto.pb.SubscriptionResponse.deserializeBinary(Buffer.from(msg, 'binary'));
err = r.getError();
if (err && err.length > 0) {
this.emit('error', new Error(r.getError()));
} else {
this.emit(doClose ? 'closed' : 'unsubscribed');
}
});
this.nc.requestOne(discoverSubject, Buffer.from(req.serializeBinary()), this.options.connectTimeout, (msg) => {
if (msg instanceof nats.NatsError) {
let err = msg;
if (msg.code === nats.REQ_TIMEOUT) {
err = new nats.NatsError(CONNECT_REQ_TIMEOUT, CONNECT_REQ_TIMEOUT, err);
}
this.closeWithError('error', err);
return;
}
const cr = proto.pb.ConnectResponse.deserializeBinary(Buffer.from(msg, 'binary'));
if (cr.getError() !== "") {
this.closeWithError('error', cr.getError());
return;
}
this.pubPrefix = cr.getPubPrefix();
this.subRequests = cr.getSubRequests();
this.unsubRequests = cr.getUnsubRequests();
this.subCloseRequests = cr.getSubCloseRequests();
this.closeRequests = cr.getCloseRequests();