@riocrypto/common-server 1.0.2253 → 1.0.2254

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.
@@ -5,6 +5,7 @@ declare class LoggerService {
5
5
  private maskValue;
6
6
  private maskSensitiveData;
7
7
  private requestMethodFilter;
8
+ private handleCustomErrorFormat;
8
9
  getLogger(): Logger;
9
10
  initLogger(): Promise<void>;
10
11
  }
@@ -94,6 +94,48 @@ class LoggerService {
94
94
  // If there's no req.method, don't filter out the log
95
95
  return info;
96
96
  });
97
+ // Custom format to handle CustomError serialization
98
+ this.handleCustomErrorFormat = (0, winston_1.format)((info) => {
99
+ let error;
100
+ // express-winston errorLogger often puts the error in info.message or info.meta.err
101
+ if (info.message instanceof Error) {
102
+ error = info.message;
103
+ }
104
+ else if (info.meta && info.meta.err instanceof Error) {
105
+ error = info.meta.err;
106
+ }
107
+ else if (info.level === "error" &&
108
+ info.message &&
109
+ typeof info.message === "object" &&
110
+ info.message.stack) {
111
+ // Sometimes the error object might be directly in message for non-express-winston logs
112
+ error = info.message;
113
+ }
114
+ if (error instanceof common_1.CustomError) {
115
+ // Replace the error object/message with serialized details
116
+ // Log serialized errors under 'errorDetails' and keep original message if it's just a string
117
+ info.errorDetails = error.serializeErrors();
118
+ if (typeof info.message === "object") {
119
+ info.message = error.message; // Keep the original error message string
120
+ }
121
+ // Prevent Winston from trying to serialize the original complex error object
122
+ if (info.meta && info.meta.err) {
123
+ delete info.meta.err;
124
+ }
125
+ }
126
+ else if (error) {
127
+ // For generic errors, ensure the stack is included if available
128
+ info.errorMessage = error.message;
129
+ info.errorStack = error.stack;
130
+ if (typeof info.message === "object") {
131
+ info.message = error.message;
132
+ }
133
+ if (info.meta && info.meta.err) {
134
+ delete info.meta.err;
135
+ }
136
+ }
137
+ return info;
138
+ });
97
139
  this.logger = null;
98
140
  }
99
141
  maskValue(value, showLastFour = false) {
@@ -124,6 +166,7 @@ class LoggerService {
124
166
  this.logger = (0, winston_1.createLogger)({
125
167
  level: logLevel,
126
168
  format: winston_1.format.combine(winston_1.format.timestamp(), this.maskSensitiveData(), this.requestMethodFilter(), // Add the request method filter
169
+ this.handleCustomErrorFormat(), // Add the custom error format
127
170
  winston_1.format.json(), winston_1.format.prettyPrint()),
128
171
  transports: transportsArray,
129
172
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.2253",
3
+ "version": "1.0.2254",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",