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)
}
})
}
deleteDoneSubsByResponse(response) {
// TODO: replace with response.requestId
if (response.type === ControlLayer.ResendResponseResent.TYPE || response.type === ControlLayer.ResendResponseNoResend.TYPE) {
delete this.subForRequestId[response.requestId]
}
}
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)
}
this.socket.onmessage = (messageEvent) => {
try {
const websocketResponse = WebsocketResponse.deserialize(messageEvent.data)
this.emit(websocketResponse.constructor.getMessageName(), websocketResponse)
} catch (err) {
this.emit('error', err)
}
}
_requestPublish(streamMessage, sessionToken) {
const request = ControlLayer.PublishRequest.create(streamMessage, sessionToken)
debug('_requestPublish: %o', request)
return this.connection.send(request)
}