Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.connection.on('error', (err) => {
// If there is an error parsing a json message in a stream, fire error events on the relevant subs
if (err instanceof Errors.InvalidJsonError) {
const stream = this._getSubscribedStreamPartition(err.streamMessage.getStreamId(), err.streamMessage.getStreamPartition())
if (stream) {
stream.getSubscriptions().forEach((sub) => sub.handleError(err))
} else {
debug('WARN: InvalidJsonError received for stream with no subscriptions: %s', err.streamId)
}
} else {
// if it looks like an error emit as-is, otherwise wrap in new Error
const errorObject = (err && err.stack && err.message) ? err : new Error(err)
this.emit('error', errorObject)
console.error(errorObject)
}
})
}
handleError(err) {
/**
* If parsing the (expected) message failed, we should still mark it as received. Otherwise the
* gap detection will think a message was lost, and re-request the failing message.
*/
if (err instanceof Errors.InvalidJsonError && err.streamMessage && this.orderingUtil) {
this.orderingUtil.markMessageExplicitly(err.streamMessage)
}
this.emit('error', err)
}