Extract Errors.redactSensitivePaths
This commit is contained in:
parent
33bbb12626
commit
0e2f8a8a06
1 changed files with 14 additions and 5 deletions
|
@ -2,7 +2,8 @@
|
|||
|
||||
const Path = require('path');
|
||||
|
||||
const toError = require('ensure-error');
|
||||
const ensureError = require('ensure-error');
|
||||
const isString = require('lodash/isString');
|
||||
|
||||
|
||||
const APP_ROOT_PATH = Path.join(__dirname, '..', '..', '..');
|
||||
|
@ -10,8 +11,16 @@ const APP_ROOT_PATH_PATTERN = new RegExp(APP_ROOT_PATH, 'g');
|
|||
|
||||
// toLogFormat :: Error -> String
|
||||
exports.toLogFormat = (error) => {
|
||||
const normalizedError = toError(error);
|
||||
const stackWithoutPrivatePaths =
|
||||
normalizedError.stack.replace(APP_ROOT_PATH_PATTERN, '<REDACTED_PATH>');
|
||||
return stackWithoutPrivatePaths;
|
||||
const normalizedError = ensureError(error);
|
||||
const stackWithRedactedPaths = exports.redactSensitivePaths(normalizedError.stack);
|
||||
return stackWithRedactedPaths;
|
||||
};
|
||||
|
||||
// redactSensitivePaths :: String -> String
|
||||
exports.redactSensitivePaths = (logLine) => {
|
||||
if (!isString(logLine)) {
|
||||
return logLine;
|
||||
}
|
||||
|
||||
return logLine.replace(APP_ROOT_PATH_PATTERN, '<REDACTED_PATH>');
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue