@bee.js/node 0.0.70 → 0.0.72

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.
Files changed (2) hide show
  1. package/beehive.js +16 -11
  2. package/package.json +1 -1
package/beehive.js CHANGED
@@ -32,35 +32,40 @@ module.exports = function hive(req = {}, res = {}, model = null) {
32
32
  let models = global.models;
33
33
  let relWhere = {};
34
34
 
35
- const dbExec = async function (SQL, binds = [], params = {}) {
35
+ const dbExec = async function (SQL, binds = [], params = {}, retryCount = 0) {
36
36
  let result = [];
37
+ const MAX_RETRIES = 2;
37
38
 
38
39
  try {
39
- if (global.configs.debug)
40
- console.log(`
41
- ${SQL}
42
- `);
40
+ if (global.configs.debug) console.log(SQL);
43
41
 
44
42
  global.beeDBPool = global.beeDBPool || beeORM.createPool(global.configs);
45
43
  result = await global.beeDBPool.query(SQL, binds);
46
44
  } catch (_error) {
47
45
  log("####################### DB ERROR #######################");
48
46
  log(_error);
49
- log(SQL);
50
- _error = e;
51
- errorCode = 502;
47
+ log({ SQL, binds });
48
+
49
+ const isConnReset = _error?.message?.includes("ECONNRESET");
50
+
51
+ if (isConnReset && retryCount < MAX_RETRIES) {
52
+ log("### DB retry after ECONNRESET...");
53
+ global.beeDBPool = beeORM.createPool(global.configs);
54
+ return await dbExec(SQL, binds, params, retryCount + 1);
55
+ }
56
+
57
+ throw _error; // error after MAX_RETRIES
52
58
  } finally {
53
59
  if (global.configs.debug) debug.push(SQL);
54
60
  if (global.configs.debug && binds) debug.push(binds);
55
61
 
56
62
  if (params.container) {
57
63
  data[params.container] = result[0];
58
-
59
64
  if (counters) counters[params.container] = (result[0] || []).length;
60
65
  }
61
-
62
- return result[0];
63
66
  }
67
+
68
+ return result[0];
64
69
  };
65
70
 
66
71
  return Object.assign({}, res, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bee.js/node",
3
- "version": "0.0.70",
3
+ "version": "0.0.72",
4
4
  "description": "A JavaScript framework for making Node.js API´s",
5
5
  "main": "index.js",
6
6
  "scripts": {