@hvedinich/utils 0.0.63 → 0.0.64

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": "@hvedinich/utils",
3
- "version": "0.0.63",
3
+ "version": "0.0.64",
4
4
  "description": "utils module",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/log/index.js CHANGED
@@ -1,10 +1,21 @@
1
1
  const pino = require('pino');
2
2
 
3
- const ctxToString = ctx => {
3
+ const ctxParser = ctx => {
4
4
  if (!ctx) return { uid: 'unknown' };
5
5
  return ctx.uid ? { uid: ctx.uid, permission: ctx.permission } : { uid: 'unknown' };
6
6
  };
7
7
 
8
+ const errorParser = error => {
9
+ if (!error) return null;
10
+ return {
11
+ stack: error.stack,
12
+ code: error.code,
13
+ message: error.message,
14
+ status: error.status,
15
+ sanitized: error.sanitized,
16
+ };
17
+ };
18
+
8
19
  const PinoLevelToSeverityLookup = {
9
20
  debug: 'DEBUG',
10
21
  info: 'INFO',
@@ -27,16 +38,16 @@ module.exports = class Logger {
27
38
  };
28
39
  },
29
40
  log: object => {
30
- const ctx = ctxToString(object?.ctx);
31
-
41
+ const ctx = ctxParser(object?.ctx);
32
42
  return { ...object, ctx };
33
43
  },
34
44
  },
35
45
  });
36
46
  }
37
47
 
38
- error(str, ctx, fields) {
39
- this.logger.error({ ctx, fields }, str);
48
+ error(str, ctx, params) {
49
+ const { error, ...fields } = params || {};
50
+ this.logger.error({ ctx, error: errorParser(error), fields }, str);
40
51
  }
41
52
 
42
53
  info(str, ctx, fields) {
@@ -23,10 +23,12 @@ const logError = (err, logger = console) => {
23
23
  `Server error`,
24
24
  {},
25
25
  {
26
- path: description.path,
27
- message: description.message,
28
- serviceName: description.serviceName,
29
- stack: description.stack,
26
+ error: {
27
+ path: description.path,
28
+ message: description.message,
29
+ serviceName: description.serviceName,
30
+ stack: description.stack,
31
+ },
30
32
  },
31
33
  );
32
34
  }
@@ -143,8 +145,14 @@ const waitServices = async (services = {}, logger = console) => {
143
145
  }
144
146
  // eslint-disable-next-line no-await-in-loop, no-promise-executor-return
145
147
  await new Promise(res => setTimeout(res, 5000));
146
- } catch (err) {
147
- logger.debug(err);
148
+ } catch (error) {
149
+ logger.error(
150
+ `waitServices error`,
151
+ {},
152
+ {
153
+ error,
154
+ },
155
+ );
148
156
  // eslint-disable-next-line no-await-in-loop, no-promise-executor-return
149
157
  await new Promise(res => setTimeout(res, 5000));
150
158
  }