diff --git a/src/index.ts b/src/index.ts index fb134259c..8e7298c0e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -32,6 +32,8 @@ process.on('unhandledRejection', (reason, promise) => { return; } + deletePropertyPath(reason, 'response.request.headers.Authorization'); + try { logger.error({ reason, promise }, 'UNHANDLED REJECTION!'); } catch (ignore) { @@ -41,6 +43,26 @@ process.on('unhandledRejection', (reason, promise) => { } }); +function deletePropertyPath(obj, path) { + if (!obj || !path) { + return; + } + + if (typeof path === 'string') { + path = path.split('.'); + } + + for (var i = 0; i < path.length - 1; i++) { + obj = obj[path[i]]; + + if (typeof obj === 'undefined') { + return; + } + } + + delete obj[path.pop()]; +} + function cleanUpTempStorage() { const { IMAGE_STORAGE_ROOT } = config; try {