Skip to content
This repository was archived by the owner on Nov 28, 2018. It is now read-only.

Commit c260b38

Browse files
author
Joshua Rubin
committed
emit an error event that must be caught by stomp users
Signed-off-by: Joshua Rubin <jrubin@zvelo.com>
1 parent c34a952 commit c260b38

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

lib/stomp.js

+16-14
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,18 @@ function _connect(stomp) {
9595
log = stomp.log;
9696

9797
if (stomp.ssl) {
98-
log.debug('Connecting to ' + stomp.host + ':' + stomp.port + ' using SSL');
99-
stomp.socket = tls.connect(stomp.port, stomp.host, stomp.ssl_options, function() {
100-
log.debug('SSL connection complete');
101-
if (!stomp.socket.authorized) {
102-
log.error('SSL is not authorized: '+stomp.socket.authorizationError);
103-
if (stomp.ssl_validate) {
104-
_disconnect(stomp);
105-
return;
106-
}
107-
}
108-
_setupListeners(stomp);
109-
});
98+
log.debug('Connecting to ' + stomp.host + ':' + stomp.port + ' using SSL');
99+
stomp.socket = tls.connect(stomp.port, stomp.host, stomp.ssl_options, function() {
100+
log.debug('SSL connection complete');
101+
if (!stomp.socket.authorized) {
102+
log.error('SSL is not authorized: '+stomp.socket.authorizationError);
103+
if (stomp.ssl_validate) {
104+
_disconnect(stomp);
105+
return;
106+
}
107+
}
108+
_setupListeners(stomp);
109+
});
110110
} else {
111111
log.debug('Connecting to ' + stomp.host + ':' + stomp.port);
112112
stomp.socket = new net.Socket();
@@ -158,13 +158,15 @@ function _setupListeners(stomp) {
158158

159159
socket.on('error', function(error) {
160160
log.error(error.stack + 'error name: ' + error.name);
161+
stomp.emit("error", error);
161162
});
162163

163164
socket.on('close', function(error) {
164165
log.debug('disconnected');
165-
if (error)
166+
if (error) {
166167
log.error('Disconnected with error: ' + error);
167-
stomp.emit("disconnected");
168+
}
169+
stomp.emit("disconnected", error);
168170
});
169171

170172
if (stomp.ssl) {

0 commit comments

Comments
 (0)