Last active
June 9, 2020 17:47
-
-
Save Sturtuk/5bf9c5e72afb538f734841b144b0e8d5 to your computer and use it in GitHub Desktop.
Add Bugsnag to your JavaScript projects to automatically capture and report errors in production.
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
window.logger = window.logger || {}; | |
logger.bugsnagKey = '<YOUR-API-KEY-HERE>'; | |
/** | |
* @Author Edwin F Sturt | |
* @Dated 2020-06-09 | |
* @uses handling javascript errors on after DOM active, User interactions | |
* @loadBugsnagLib Promise based method | |
**/ | |
const loadBugsnagLib = load => { | |
var script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
script.src = 'https://d2wy8f7a9ursnm.cloudfront.net/v7/bugsnag.min.js'; | |
document.head.appendChild(script); | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
try { | |
version = "Bugsnag loaded "; | |
resolve(version) | |
} catch(err) { | |
reject(new Error('Bugsnag not loaded')); | |
} | |
}, 1000) | |
}) | |
}; | |
/** | |
* @Author Edwin F Sturt | |
* @Dated 2020-06-09 | |
* @uses handling javascript errors on after DOM active, User interactions | |
* @loadBugsnagLib Promise based method | |
**/ | |
loadBugsnagLib('start') | |
.then(function (data) { | |
console.log('library loaded') | |
}) | |
.finally(function(){ | |
logger.log = Bugsnag.start(logger.bugsnagKey) | |
}) | |
.catch(function (err) { | |
console.log('Bugsnag library not loaded: problem -> ' + err) | |
}); | |
// Custom error handling method -> logger.log.notify |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment