Sentry-javascript: Global promise catch

Created on 3 Oct 2017  路  9Comments  路  Source: getsentry/sentry-javascript

https://docs.sentry.io/clients/javascript/usage/#promises

Would be nice to have a global promise catch for sentry.

Help Wanted Confirmed Feature

Most helpful comment

Ah, it's raven-js, not raven-node... I jump between those too often, sorry.
I'll take a look into this soon.

All 9 comments

What's wrong with setting it up using?:

window.onunhandledrejection = function(evt) {
    Raven.captureException(evt.reason);
};

@kamilogorek raven-node has an option to do it; we should probably do the same. evt.reason is often not accurate (or actually an error), so if we could do some smoothing out in our integration that could be ideal.

I think we should table it.

@kamilogorek @benvinegar I need it for ES6 for javascript (browser based).
I would like to catch errors in 'catch' function to send Sentry. If I send errors with Raven.captureException() method. I have to write the function into all Promise's catch functions.
It sounds terrifying.

Promise.then(() => { // a syntax error or called reject() method }).catch(err => { // handled error })

Could you suggest the best way to do it?

Ah, it's raven-js, not raven-node... I jump between those too often, sorry.
I'll take a look into this soon.

Hello again, Is there any progress about it? :) @kamilogorek

just a bump, I think it would be nice to handle this. is it as easy as an event listener?

This would be a very nice feature.

It is kinda easy @MaxBittker,

window.addEventListener('unhandledrejection', function (evt) {
  Raven.captureException(evt.reason)
})

However, only Chrome supports it... even though it's 2018 already :|

Released as 3.23.0 \o/

Was this page helpful?
0 / 5 - 0 ratings