@emartech/json-logger 3.3.0 → 3.5.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/.npmignore ADDED
@@ -0,0 +1,4 @@
1
+ *.spec.js
2
+ node_modules
3
+ .idea
4
+ examples
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emartech/json-logger",
3
- "version": "3.3.0",
3
+ "version": "3.5.0",
4
4
  "description": "Tiny and fast json logger with namespace support",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -48,6 +48,10 @@ class Logger {
48
48
  }
49
49
 
50
50
  _shortenStackTrace(stack) {
51
+ if (typeof stack === 'undefined') {
52
+ return;
53
+ }
54
+
51
55
  return stack.length > STACK_TRACE_LIMIT
52
56
  ? stack.substring(0, STACK_TRACE_LIMIT) + ' ...'
53
57
  : stack;
@@ -66,22 +70,30 @@ class Logger {
66
70
  }
67
71
 
68
72
  _getErrorDetails(error) {
69
- const details = {
73
+ if (!(error instanceof Object)) {
74
+ return {};
75
+ }
76
+
77
+ const baseDetails = {
70
78
  error_name: error.name,
71
79
  error_stack: this._shortenStackTrace(error.stack),
72
80
  error_message: error.message,
73
81
  error_data: this._shortenData(error.data)
74
82
  };
75
83
 
76
- if (error.isAxiosError) {
77
- details.request_method = error.config.method;
78
- details.request_url = error.config.url;
79
- details.response_status = error.response.status;
80
- details.response_status_text = error.response.statusText;
81
- details.response_data = this._shortenData(error.response.data);
82
- }
84
+ return Object.assign(baseDetails, this._getAxiosErrorDetails(error));
85
+ }
83
86
 
84
- return details;
87
+ _getAxiosErrorDetails(error) {
88
+ if (!error.isAxiosError) return {};
89
+
90
+ return {
91
+ request_method: error.config.method,
92
+ request_url: error.config.url,
93
+ response_status: error.response ? error.response.status : undefined,
94
+ response_status_text: error.response ? error.response.statusText : undefined,
95
+ response_data: error.response ? this._shortenData(error.response.data) : undefined
96
+ };
85
97
  }
86
98
  }
87
99
 
@@ -92,7 +104,7 @@ Logger.config = {
92
104
  };
93
105
 
94
106
  const logMethodFactory = function(level) {
95
- return function(action, data) {
107
+ return function(action, data = {}) {
96
108
  if (!this._enabled) {
97
109
  return;
98
110
  }