You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by jk...@apache.org on 2017/01/25 04:32:36 UTC

thrift git commit: THRIFT-3926 There should be an error emitted when http status code is not 200 Client: nodejs Patch: lifei

Repository: thrift
Updated Branches:
  refs/heads/master b62247e0e -> 3d6e2a507


THRIFT-3926 There should be an error emitted when http status code is not 200
Client: nodejs
Patch: lifei <li...@bytedance.com>

This closes #1086


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/3d6e2a50
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/3d6e2a50
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/3d6e2a50

Branch: refs/heads/master
Commit: 3d6e2a507159e51d486e4e2674a1dca5fc227279
Parents: b62247e
Author: James E. King, III <jk...@apache.org>
Authored: Tue Jan 24 23:29:52 2017 -0500
Committer: James E. King, III <jk...@apache.org>
Committed: Tue Jan 24 23:31:54 2017 -0500

----------------------------------------------------------------------
 lib/nodejs/lib/thrift/http_connection.js | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/3d6e2a50/lib/nodejs/lib/thrift/http_connection.js
----------------------------------------------------------------------
diff --git a/lib/nodejs/lib/thrift/http_connection.js b/lib/nodejs/lib/thrift/http_connection.js
index 18bfadb..163e5b7 100644
--- a/lib/nodejs/lib/thrift/http_connection.js
+++ b/lib/nodejs/lib/thrift/http_connection.js
@@ -169,6 +169,10 @@ var HttpConnection = exports.HttpConnection = function(host, port, options) {
     var data = [];
     var dataLen = 0;
 
+    if (response.statusCode !== 200) {
+      this.emit("error", new THTTPException(statusCode, response));
+    }
+
     response.on('error', function (e) {
       self.emit("error", e);
     });
@@ -236,3 +240,14 @@ exports.createHttpConnection = function(host, port, options) {
 
 exports.createHttpClient = createClient
 
+
+function THTTPException(statusCode, response) {
+  thrift.TApplicationException.call(this);
+  Error.captureStackTrace(this, this.constructor);
+  this.name = this.constructor.name;
+  this.statusCode = statusCode;
+  this.response = response;
+  this.type = thrift.TApplicationExceptionType.PROTOCOL_ERROR;
+  this.message = "Received a response with a bad HTTP status code: " + response.statusCode;
+}
+util.inherits(THTTPException, thrift.TApplicationException);
\ No newline at end of file