Skip to content

Commit

Permalink
refactor extraerrorata
Browse files Browse the repository at this point in the history
  • Loading branch information
naseemkullah committed Oct 1, 2021
1 parent f96d47b commit ba2c9c1
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions packages/integrations/src/extraerrordata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,23 @@ export class ExtraErrorData implements Integration {
* Extract extra information from the Error object
*/
private _extractErrorData(error: ExtendedError): { [key: string]: unknown } | null {
let result = null;
// We are trying to enhance already existing event, so no harm done if it won't succeed
try {
const nativeKeys = ['name', 'message', 'stack', 'line', 'column', 'fileName', 'lineNumber', 'columnNumber'];
const errorKeys = Object.getOwnPropertyNames(error).filter(key => nativeKeys.indexOf(key) === -1);
const errorKeys = Object.getOwnPropertyNames(error).filter(key => !nativeKeys.includes(key));

if (errorKeys.length) {
const extraErrorInfo: { [key: string]: unknown } = {};
for (const key of errorKeys) {
let value = error[key];
if (isError(value)) {
value = (value as Error).toString();
}
extraErrorInfo[key] = value;
const value = error[key];
extraErrorInfo[key] = isError(value) ? (value as Error).toString() : value;
}
result = extraErrorInfo;
return extraErrorInfo;
}
} catch (oO) {
logger.error('Unable to extract extra data from the Error object:', oO);
}

return result;
return null;
}
}

0 comments on commit ba2c9c1

Please sign in to comment.