Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#1181 | errbit | using stacktrace-js to expa…
Browse files Browse the repository at this point in the history
…nd on minified backtrace for errors
  • Loading branch information
snyaggarwal committed Jan 13, 2022
1 parent 0f94537 commit c4ad25f
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions src/components/common/ErrorBoundary.jsx
@@ -1,8 +1,10 @@
/*eslint no-process-env: 0*/
import React from 'react';
import ErrorUI from './ErrorUI';
import { getCurrentUser, getEnv } from '../../common/utils';
import StackTrace from "stacktrace-js";
import { Notifier } from '@airbrake/browser';
import { map } from 'lodash';
import { getCurrentUser, getEnv } from '../../common/utils';
import ErrorUI from './ErrorUI';

class ErrorBoundary extends React.Component {
constructor(props) {
Expand All @@ -29,18 +31,31 @@ class ErrorBoundary extends React.Component {
}

componentDidCatch(error, errorInfo) {
this.setState({error: error, errorInfo: errorInfo, hasError: Boolean(error)}, () => {
const notifier = this.getNotifier()
if(notifier) {
const user = getCurrentUser() || {};
notifier.notify({
error: this.state.error,
params: {info: this.state.errorInfo},
context: {
component: window.location.href, user: {id: user.id, email: user.email}
}
});
}
StackTrace.fromError(error).then(traces => {
const newTraces = map(traces, trace => ({
column: trace.columnNumber,
file: trace.fileName,
'function': trace.functionName,
line: trace.lineNumber
}));

this.setState({error: error, errorInfo: errorInfo, hasError: Boolean(error)}, () => {
const notifier = this.getNotifier()
if(notifier) {
const user = getCurrentUser() || {};
notifier.addFilter(notice => {
notice.errors[0].backtrace = newTraces;
return notice;
});
notifier.notify({
error: this.state.error,
params: {info: this.state.errorInfo},
context: {
component: window.location.href, user: {id: user.id, email: user.email}
}
});
}
})
})
}

Expand Down

0 comments on commit c4ad25f

Please sign in to comment.