Created
February 28, 2018 02:15
-
-
Save binhqd/c28c4e8d283b670b2115cd09360168e4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let airbrakeJs = require('airbrake-js'); | |
let StackTrace = require('stacktrace-js'); | |
import { | |
TRACKER_URL, | |
ENV | |
} from 'constants/config'; | |
// handling all window errors | |
let airbrake = new airbrakeJs({ | |
projectId: 'f5618c7df1dbcd6181c3266abfac85eb', | |
projectKey: 'f5618c7df1dbcd6181c3266abfac85eb', | |
reporter: 'xhr', | |
host: TRACKER_URL || 'http://your-tracker-url.com' | |
}); | |
airbrake.addFilter(function(notice) { | |
notice.errors[0].backtrace = notice.context.traces; | |
notice.context.environment = ENV; | |
return notice; | |
}); | |
window.onerror = (msg, url, lineNo, columnNo, error) => { | |
StackTrace.fromError(error).then((traces) => { | |
let newTraces = []; | |
traces.map(trace => { | |
let newTrace = { | |
column: trace.columnNumber, | |
file: trace.fileName, | |
function: trace.functionName, | |
line: trace.lineNumber | |
} | |
newTraces.push(newTrace); | |
}); | |
airbrake.notify({ | |
error: error, | |
context: { | |
traces: newTraces | |
} | |
}); | |
}).catch(errback => { | |
console.log(errback) | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment