Skip to content

Commit bf05b11

Browse files
authored
Merge pull request #61 from TeamHive/fix/remove-sanitize-error
Fix/remove sanitize error
2 parents b64f0a1 + 505e081 commit bf05b11

File tree

2 files changed

+5
-57
lines changed

2 files changed

+5
-57
lines changed

src/modules/exceptions/base.exception.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ export class BaseException extends HttpException {
55
[key: string]: any;
66
};
77

8+
tags: {
9+
[key: string]: number | string | boolean | bigint | symbol | null | undefined;
10+
};
11+
812
error: Error;
913

1014
loggedMetadata: any;

src/modules/services/error-handler/error-handler.service.ts

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Inject, Injectable, Optional } from '@nestjs/common';
22
import { StaticErrorHandlerConfiguration, StaticErrorHandlerService } from '@teamhive/node-common';
33
import { Logger } from 'log4js';
44
import { ApplicationTokens } from '../../application-tokens.const';
5-
import { BaseException } from '../../exceptions';
65
import { Breadcrum } from '../../interfaces/breadcrum.interface';
76
import { ErrorHandlerConfigurationToken } from '../../providers/error-handler-configuration/error-handler-configuration.provider';
87
@Injectable()
@@ -32,65 +31,10 @@ export class ErrorHandler {
3231
}
3332

3433
captureException(error: Error) {
35-
StaticErrorHandlerService.captureException(this.sanitizeError(error), this.logger, this.errorHandlerConfiguration);
34+
StaticErrorHandlerService.captureException(error, this.logger, this.errorHandlerConfiguration);
3635
}
3736

3837
captureMessage(message: string) {
3938
StaticErrorHandlerService.captureMessage(message, this.logger);
4039
}
41-
42-
sanitizeError(error: Error) {
43-
const sanitizeException = this.errorHandlerConfiguration.sanitizeException ?? true;
44-
if (!sanitizeException) {
45-
return error;
46-
}
47-
let name: string;
48-
let message: string;
49-
let stack: string;
50-
let loggedMetadata: any;
51-
let prototype: any;
52-
if (error instanceof BaseException) {
53-
const exception = error;
54-
const subError = exception.error;
55-
if (subError) {
56-
name = subError.name !== 'Error' ? subError.name : undefined;
57-
stack = subError.stack;
58-
message = subError.message;
59-
}
60-
if (!name) {
61-
name = exception.name !== 'Error' ? exception.name : undefined;
62-
}
63-
if (!stack) {
64-
stack = exception.stack;
65-
}
66-
if (!message) {
67-
message = exception.message;
68-
}
69-
prototype = Object.getPrototypeOf(exception);
70-
loggedMetadata = exception.loggedMetadata;
71-
}
72-
else {
73-
name = error.name;
74-
message = error.message;
75-
stack = error.stack;
76-
prototype = Object.getPrototypeOf(error);
77-
}
78-
const sanitizedError = new Error(message);
79-
sanitizedError.stack = stack;
80-
sanitizedError.message = message;
81-
(sanitizedError as any).loggedMetadata = loggedMetadata;
82-
(sanitizedError as any).__proto__ = prototype;
83-
84-
// if there isn't a specific name given, clear the name so the constructor name is used
85-
if (name) {
86-
sanitizedError.name = name;
87-
}
88-
else {
89-
// clear the name on the object
90-
sanitizedError.name = undefined;
91-
// remove the key from the error
92-
delete sanitizedError.name;
93-
}
94-
return sanitizedError;
95-
}
9640
}

0 commit comments

Comments
 (0)