THRIFT-3927: Emit an error instead of throw an error in the async callback
Client: node
Patch: lifei

Because the data event of a connection is async handled, throw an exception can not tell the code the error. emit the error should be the correct way to handle the errors.

Closes #1087
diff --git a/lib/nodejs/lib/thrift/connection.js b/lib/nodejs/lib/thrift/connection.js
index 23cb01c..575d516 100644
--- a/lib/nodejs/lib/thrift/connection.js
+++ b/lib/nodejs/lib/thrift/connection.js
@@ -150,7 +150,7 @@
         transport_with_data.rollbackPosition();
       }
       else {
-        throw e;
+        self.emit('error', e);
       }
     }
   }));
diff --git a/lib/nodejs/lib/thrift/http_connection.js b/lib/nodejs/lib/thrift/http_connection.js
index f3fcd74..18bfadb 100644
--- a/lib/nodejs/lib/thrift/http_connection.js
+++ b/lib/nodejs/lib/thrift/http_connection.js
@@ -157,7 +157,7 @@
       if (e instanceof InputBufferUnderrunError) {
         transport_with_data.rollbackPosition();
       } else {
-        throw e;
+        self.emit('error', e);
       }
     }
   }