Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function onError () {
console.log('calling notify() with an onError callback…')
// onError can be used to modify a report or prevent it from being sent at all
// this example pseudo-randomly filters out approximately half of the reports
Bugsnag.notify(new Error('sometimes will send'), (event) => {
const n = Math.random()
if (n <= 0.5) return false
})
}
function handledError () {
console.log('notifying of a handled error…')
// you can notify Bugsnag of errors you handled or created yourself
Bugsnag.notify(new Error('scheduling clash'))
}
function onError () {
console.log('calling notify() with a onError callback…')
// onError can be used to modify a report or prevent it from being sent at all
// this example pseudo-randomly filters out approximately half of the reports
Bugsnag.notify(new Error('sometimes will send'), (event) => {
const n = Math.random()
if (n <= 0.5) return false
})
}
triggerHandledError() {
this.doAHandledError = true;
try {
// potentially buggy code goes here
var niceCode = "Everything is fine here.";
throw("Bad thing!");
} catch (e) {
// below modifies the handled error, and then sends it to your dashboard.
Bugsnag.notify(e, event => {
event.context = 'Don\'t worry - I handled it!'
});
}
// resets the button
setTimeout(function () {
this.doAHandledError = false;
}.bind(this), 1000);
}
errors.forEach(({ error }) => Bugsnag.notify(error, event => event.addMetadata('route', route)))
})
.catch((e) => {
Bugsnag.notify(e)
handler(new HandledError(defaultError.message))
})
}
useEffect(() => {
if (!error) {
return
}
if (error instanceof Error) {
Bugsnag.notify(error)
handler(new HandledError(defaultError.message))
} else if (error instanceof Response) {
error
.clone()
.json()
.then((res: { error: APIError }) => {
handler(new HandledError(res.error.message))
})
.catch((e) => {
Bugsnag.notify(e)
handler(new HandledError(defaultError.message))
})
}
}, [defaultError, error, handler])
const handleError = (error: Error) => {
if (error.name === 'HandledError') {
return
}
Bugsnag.notify(error)
}