W
W
wlms2019-01-03 01:53:27
MySQL
wlms, 2019-01-03 01:53:27

JugglingDb how to catch connect?

I want to connect to mySQL database.

const Schema = require('jugglingdb').Schema;
const schema = new Schema('mysql', {
      host: host,
      username: user,
      password: password,
      tableName : tableName,
      database: ddbname,
      port: port
   });

When all the data is correct, the connection goes well. But when the data is NOT correct, an exception is thrown and an infinite reconnect occurs.
connection.connect err { Error: connect ECONNREFUSED 127.0.0.11:3306
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1117:14)
    --------------------
    at Protocol._enqueue (E:\Web\apc-nodejs\node_modules\mysql\lib\protocol\Protocol.js:144:48)
    at Protocol.handshake (E:\Web\apc-nodejs\node_modules\mysql\lib\protocol\Protocol.js:51:23)
    at Connection.connect (E:\Web\apc-nodejs\node_modules\mysql\lib\Connection.js:118:18)
    at initializeConnection (E:\Web\apc-nodejs\node_modules\jugglingdb-mysql\lib\mysql.js:53:20)
    at Object.initializeSchema [as initialize] (E:\Web\apc-nodejs\node_modules\jugglingdb-mysql\lib\mysql.js:34:5)
    at new Schema (E:\Web\apc-nodejs\node_modules\jugglingdb\lib\schema.js:106:13)
    at router.post (E:\Web\apc-nodejs\routes\addApp.js:25:22)
    at Layer.handle [as handle_request] (E:\Web\apc-nodejs\node_modules\router\lib\layer.js:93:5)
    at next (E:\Web\apc-nodejs\node_modules\router\lib\route.js:138:13)
    at Route.dispatch (E:\Web\apc-nodejs\node_modules\router\lib\route.js:109:3)
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.11',
  port: 3306,
  fatal: true }
will reconnect in 60 secs

I guess
connection.connect
is an (object?) of mySQL itself and the question is: how to catch this exception in case of incorrectly entered data and execute disconnect()?
Studied the Jugglingdb doc and schema and schema objects. No hint of handling this error.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question