How to handle MySQLStore connection error?

2021-05-09T03:06:50

I'm using NodeJS with express. I'm store the sessions to a MySQLStore (express-mysql-session) My question is how can i handle connection error? When it can't connect i want to render a page to the users instead of the "Error: connect ECONNREFUSED 127.0.0.1:3306 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1137:16) ....." message.

My code:

const MySQLStore = require('express-mysql-session')(session);
(....)
app.use(session({
  secret: 'something',
  resave: false,
  saveUninitialized: false,
  store: new MySQLStore({
    host: something,
    user: something,
    password: something,
    database: something
  }),
  cookie: {
    maxAge: 7 * 24 * 60 * 60 * 1000
  }
}));

With the simple mysqljs i could do it easily because when i use connection.query there is an (error, result) => { ... } where i can handle error but at this MySQLStore i have no clue how to handle connection error.

Copyright License:
Author:「South3492」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/67451203/how-to-handle-mysqlstore-connection-error

About “How to handle MySQLStore connection error?” questions

I'm using NodeJS with express. I'm store the sessions to a MySQLStore (express-mysql-session) My question is how can i handle connection error? When it can't connect i want to render a page to the ...
I am attempting to make a connection to a MySQL database using Express and Mariadb. The IP for the database changes while I move the PI that it is connected to from the office to my Home. If I don't
I am having issues setting sessions on one request and getting them on another page request. I am using the mysqlstore package which was recommended on the gorilla sessions github page under the "...
I am using the following to check for (internet) connection errors in my spider.py: def start_requests(self): for url in self.start_urls: yield scrapy.Request(url, callback=self.parse,
I'm new to ExpressJS (just 3 months) and I'm trying to make a project to get some hands on practice of what I have learned so far. I have tried writing a module to handle express session. But it d...
I have an express database that connects to multiple redis servers by receiving the connection ip from a client. It works fine if the redis database exists. The problem im facing is that if the ip ...
I'm using libCurl in multi-threaded way (curl_multi_perform), but don't know how to implement things so that I could handle the case of losing network connection (or any HTTP error). looks it never
how to handle mongoose connection error in try catch block?. I want to use application db connection with async function. class App { async dbconnect() { try { mongoose.connect("mongo...
i using quickfix c++ when i want store data to mysql db and using MySQLStoreFactory class(include with mysqlstore.h) it show top error i also included mysql include path and libs but didn't chang...
I'm trying to connect one Socket with one ServerSocket, but when de socket fails, the error "Connection reset" show up in the Server, how can I handle this?

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.