Skip to content

Commit 50ca58d

Browse files
feat(logger): add error cause logging
DIME-8714 Co-authored-by: Balint Barki <[email protected]>
1 parent 51b4ec5 commit 50ca58d

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/logger/logger.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,24 @@ export class Logger {
178178
}
179179

180180
return {
181-
error: {
182-
type: error.name,
183-
message: error.message,
184-
context: this.shortenData((error as ErrorWithData).data),
185-
stack_trace: this.shortenStackTrace(error.stack || ''),
186-
},
181+
error: this.extractError(error),
187182
event: {
188183
reason: error.message,
189184
},
190185
};
191186
}
192187

188+
private extractError(error: Error): unknown {
189+
const shortenedData = this.shortenData((error as ErrorWithData).data);
190+
return {
191+
type: error.name,
192+
message: error.message,
193+
...(shortenedData && { context: shortenedData }),
194+
stack_trace: this.shortenStackTrace(error.stack || ''),
195+
...(error.cause instanceof Error && { cause: this.extractError(error.cause) })
196+
};
197+
}
198+
193199
private getAxiosErrorDetails(error: AxiosError) {
194200
if (!error.isAxiosError) {
195201
return {};

tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
/* Language and Environment */
1616
"target": "es2020", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
1717
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
18+
"lib": [
19+
"ES2022.Error"
20+
],
1821
// "jsx": "preserve", /* Specify what JSX code is generated. */
1922
"experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
2023
"emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */

0 commit comments

Comments
 (0)