@sera4/essentia 1.0.39 → 1.0.41

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.
@@ -0,0 +1,38 @@
1
+ const logger = require("../logger/s4-logger");
2
+ let enabled = false;
3
+
4
+ module.exports = {
5
+ debug(...args) {
6
+ if (enabled) {
7
+ logger.debug(":: HealthCheck ::", args);
8
+ }
9
+ },
10
+
11
+ log(...args) {
12
+ if (enabled) {
13
+ logger.debug(":: HealthCheck ::", args);
14
+ }
15
+ },
16
+
17
+ warn(...args) {
18
+ if (enabled) {
19
+ logger.warn(":: HealthCheck ::", args);
20
+ }
21
+ },
22
+
23
+ info(...args) {
24
+ if (enabled) {
25
+ logger.info(":: HealthCheck ::", args);
26
+ }
27
+ },
28
+
29
+ error(...args) {
30
+ if (enabled) {
31
+ logger.error(":: HealthCheck ::", args);
32
+ }
33
+ },
34
+
35
+ setEnabled(e) {
36
+ enabled = e;
37
+ }
38
+ }
package/health/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict"
2
2
 
3
3
  const pathHelper = require("path");
4
+ const logger = require("./health-logger");
4
5
 
5
6
  class HealthCheckError extends Error {
6
7
  constructor(m) {
@@ -22,7 +23,9 @@ class HealthCheckError extends Error {
22
23
  *
23
24
  */
24
25
  class HealthCheck {
25
- constructor(appendData = {}) {
26
+ constructor(appendData = {}, enableLogging = true) {
27
+ logger.setEnabled(enableLogging);
28
+
26
29
  this.defaultResponse = {
27
30
  ...
28
31
  appendData,
@@ -31,6 +34,7 @@ class HealthCheck {
31
34
  };
32
35
 
33
36
  this.defaultPathRoute = `health_check\(.*\)?`
37
+ this.suppressLogs = false;
34
38
  this.lastCallId = 0; // default start point/integer
35
39
  this.healthChecks = [];
36
40
  }
@@ -89,6 +93,8 @@ class HealthCheck {
89
93
  await hc.healthFunction();
90
94
  return { ...res, "result": "success" };
91
95
  } catch(e) {
96
+ const appendStatus = e.status ? ` (${e.status})` : ""
97
+ logger.warn(`${hc.name} service failed${appendStatus}` )
92
98
  return { ...res, "result": "fail", status: e.status }
93
99
  }
94
100
  }
@@ -130,16 +136,16 @@ class HealthCheck {
130
136
  ... payload,
131
137
  "healthy": false,
132
138
  "message": "fail",
133
- "services": [result]
139
+ "services": result
134
140
  });
135
- } else if (status === 200) {
136
- res.status(status).json(payload);
137
- } else if (nonCriticalFailure) {
141
+ } else if (nonCriticalFail) {
138
142
  res.status(status).json({
139
143
  ... payload,
140
144
  "message": "fail",
141
- "services": [result]
145
+ "services": result
142
146
  });
147
+ } else if (status === 200) {
148
+ res.status(status).json(payload);
143
149
  }
144
150
  } else {
145
151
  let status_message;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sera4/essentia",
3
- "version": "1.0.39",
3
+ "version": "1.0.41",
4
4
  "description": "A library of utilities for Teleporte Web Services",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/package.tar.gz CHANGED
Binary file