Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_sendRequestHandler(response) {
const self = this
if (response.code && response.code === NATS.REQ_TIMEOUT) {
self._timeoutHandler()
return
}
const res = self._clientDecoder(response)
self.response.payload = res.value
self.response.error = res.error
// decoding error
if (self.response.error) {
const internalError = new Errors.ParseError('Client payload decoding', self.errorDetails).causedBy(
self.response.error
)
self.log.error(internalError)
self._execute(self.response.error)
return
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.conn.requestOne(subject, JSON.stringify(request), {}, timeout, resp => {
if (resp instanceof nats.NatsError && resp.code === nats.REQ_TIMEOUT) {
return callback(resp)
}
let response
try {
response = JSON.parse(resp)
} catch (err) {
return callback(err)
}
if (response.kind !== request.kind) {
return callback(new Error(`Invalid response ${response.kind}`))
}
callback(null, response)