Is this a bug with browser-connector error handling


#1

Hi, In the code below
a) I can catch “sqlError” correctly
b) I can catch “connectionError” for required parameter missing check( i.e. user is required )
c) however. is the required parmeters are supplied by the values are incorrect (e.g. incorrect host name) then the “error” value of the connection callback is null

Looks like a bug to me? How can I catch invalid connection parameter errors?

My code looks like this:

----


function ExecuteQuery(sql) {
        return new Promise(function (resolve, reject) {

            new Connector()
                .protocol("http")
                .host("localhost")
                .port("9092")
                .dbName("mapd")
                .user("mapd")
                .password("HyperInteractive")
                .connect((connectError, session) => { // eslint-disable-line consistent-return
                    if (connectError) {
                        reject(connectError);
                    }
                    session.query(sql, defaultQueryOptions, (sqlError, data) => {
                        if (sqlError) {
                            reject(sqlError)
                        }
                        resolve(data)
                    })
                })
        })
    }


---

Thanks,

Garth


#2

The way the Thrift TXHRTransport type is flushed prevents connection errors from being caught.

Specifically, it only calls the client callback on success (readyState 0 and status 200).

This has since been fixed in the most recent thrift.js implementation v1.0.0 (see here); however, mapd-connector is still using version 0.9.3 and there are no concrete plans to upgrade to version 1.0.0.

In the meantime, to catch connection errors, you can simply add:

xreq.onerror = (function() {
  var clientCallback = callback;
  return function() {
    clientCallback();
  };
}());

after the xreq.onreadystatechange assignment in the flush method declaration of Thrift.TXHRTransport.prototype.