THRIFT-3926 There should be an error emitted when http status code is not 200
Client: nodejs
Patch: lifei <lifei@bytedance.com>
This closes #1086
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 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.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