Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the best way to handle a connection failure when using createPool. ? #200

Closed
alexporto2200 opened this issue Apr 28, 2022 · 3 comments

Comments

@alexporto2200
Copy link

Today I'm dealing with the following way, but I can't capture the expectation.
Sorry for my lack of experience.

export class MariadbMananger {
    public pool: Pool;
    constructor(parametersConnection: ParametersMariadbMananger | null) {
        try {
            if (parametersConnection) {
                this.pool = mariadb.createPool(parametersConnection);
            } else {
                this.pool = mariadb.createPool({
                    host: Config.mariadb.host,
                    user: Config.mariadb.user,
                    password: Config.mariadb.password,
                    port: Config.mariadb.port,
                    database: Config.mariadb.database,
                    connectionLimit: 20,
                    ssl: {
                        ca: Config.mariadb.cacert,
                        cert: Config.mariadb.clientcert,
                        key: Config.mariadb.clientkey,
                        rejectUnauthorized: false
                    }
                })
            }
        } catch (e) {
            this.pool = {} as Pool
            console.log('Error connection mariadb')
        }
    }
}

And I always get the error.

Error: connect ECONNREFUSED 127.0.0.1:3306
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1146:16)
 From event:
    at _registerHandshakeCmd (/nsource/nsource/node_modules/mariadb/lib/connection.js:745:11)
    at /nsource/nsource/node_modules/mariadb/lib/connection.js:57:11
    at new Promise (<anonymous>)
    at Connection.connect (/nsource/nsource/node_modules/mariadb/lib/connection.js:56:16)
    at createConnectionPoolPromise (/nsource/nsource/node_modules/mariadb/lib/pool-promise.js:31:8)
    at creationTryout (/nsource/nsource/node_modules/mariadb/lib/pool-base.js:373:9)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 3306,
  fatal: true
}

I would like to handle the error, log a specific file and ignore it.

@rusher
Copy link
Collaborator

rusher commented Apr 29, 2022

please use stackoverflow for question like this.
ECONNREFUSED => port is not open. you have no mariadb server on 127.0.0.1:3306

@rusher rusher closed this as completed Apr 29, 2022
@alexporto2200
Copy link
Author

@rusher I think I didn't explain it right.
I know the bank is not working. I stopped him.
I would just like to capture the error it generates, from connection ECONNREFUSED in the api, so this error is printed directly on the console and does not enter the exception.
would there be any way to capture this through the exception?

@whitebyte
Copy link

Could be related to #180

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants