Skip to content

Commit

Permalink
Move error handler to before socket connecting
Browse files Browse the repository at this point in the history
  • Loading branch information
sergi committed Nov 21, 2012
1 parent f44ae03 commit 5f09ad1
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/jsftp.js
Expand Up @@ -116,7 +116,6 @@ Ftp.getPasvPort = function(text) {
var input = function(next, stop) {
_socket.on("data", next);
_socket.on("end", stop);
_socket.on("error", stop);
_socket.on("close", stop);
};

Expand Down Expand Up @@ -144,7 +143,10 @@ Ftp.getPasvPort = function(text) {
// Stream of FTP commands from the client.
S.append(S.list(null), function(next, stop) { cmd = next; })
)
(parse, function() { self.emitter.emit("disconnect", "disconnect"); });
(parse, function(hadError) {
if (!hadError) // Error case handled by error event.
self.emitter.emit("disconnect", "Ftp disconnected.");
});

if (this.waitingForEnqueue.length > 0) {
this.cmdQueue._update.apply(null, this.waitingForEnqueue);
Expand Down Expand Up @@ -247,6 +249,15 @@ Ftp.getPasvPort = function(text) {
self.destroy();
});

this.socket.on("error", function(err) {
var errString = "Error on ftp socket: " + err;
self.emitter.emit("disconnect", errString);

// We still want the error to appearin the logs if we are not in debug mode.
if (!DEBUG_MODE)
console.error(errString);
});

this.socket.on("connect", function() {
self.connecting = false;
self.emitter.emit("connect", "connect");
Expand Down

0 comments on commit 5f09ad1

Please sign in to comment.