@ejfdelgado/ejflab-back 1.30.11 → 1.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ejfdelgado/ejflab-back",
3
- "version": "1.30.11",
3
+ "version": "1.31.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ejfdelgado/ejflab-back.git"
@@ -0,0 +1,30 @@
1
+ export class consoleSrv {
2
+ static getLogLevel() {
3
+ let current = process.env.LOGLEVEL;
4
+ if (!current) {
5
+ current = "error";
6
+ }
7
+ return current;
8
+ }
9
+ static info(...args) {
10
+ this.log(...args);
11
+ }
12
+ static log(...args) {
13
+ const level = consoleSrv.getLogLevel();
14
+ if (["info"].indexOf(level) >= 0) {
15
+ console.log(...args);
16
+ }
17
+ }
18
+ static warning(...args) {
19
+ const level = consoleSrv.getLogLevel();
20
+ if (["warning", "info"].indexOf(level) >= 0) {
21
+ console.warn(...args);
22
+ }
23
+ }
24
+ static error(...args) {
25
+ const level = consoleSrv.getLogLevel();
26
+ if (["error", "warning", "info"].indexOf(level) >= 0) {
27
+ console.error(...args);
28
+ }
29
+ }
30
+ }
@@ -147,6 +147,16 @@ export class PostgresSrv {
147
147
  database: params.database,
148
148
  connectionTimeoutMillis: parseInt(params.timeout),
149
149
  });
150
+ PostgresSrv.pool.on('error', (err) => {
151
+ // try reconnect given the tipe of error
152
+ console.log("-------------------------------------");
153
+ console.log("------------------ Handling error ---");
154
+ console.log("-------------------------------------");
155
+ console.log(JSON.stringify(err.message));
156
+ if (err.message == "read ETIMEDOUT") {
157
+ PostgresSrv.createPool();
158
+ }
159
+ });
150
160
  }
151
161
 
152
162
  static async checkSelect1() {