Sentry-react-native: How to ignore sentry errors in @sentry/react-native, previously we used `setShouldSendCallback` which is no longer available?

Created on 2 Oct 2019  路  2Comments  路  Source: getsentry/sentry-react-native

OS:

  • [ ] Windows
  • [x] MacOS
  • [ ] Linux

_Platform:_

  • [x] iOS
  • [x] Android

SDK:

  • [x] @sentry/react-native
  • [ ] react-native-sentry

react-native version: 0.60.5

Init Code:

Sentry.init({
  dsn: 'https://[email protected]/...'
});

In the old api with react-native-sentry we would use the following to ignore errors:

const ignoreErrors = [
  /^ValidationError:/,
  /Network Error/,
  /status code 401/
]

Sentry.setShouldSendCallback((event) => {
    let allow = true
    const errors = get(event, "exception.values")
    if (Array.isArray(errors)) {
      errors.forEach((err) => {
        ignoreErrors.forEach((regex) => {
          if (err.value.match(regex)) {
            allow = false
          }
        })
      })
    }

    const sentryIgnoreError = get(event, "extra.error.config.sentryIgnoreError")
    if (Array.isArray(sentryIgnoreError)) {
      const code = get(event, "extra.error.response.code")
      if (sentryIgnoreError.indexOf(code) > -1) {
        allow = false
      }
    }

    return allow
  })

How we do this with @sentry/react-native?

Most helpful comment

Yes, beforeSend should be used.
And yes sorry you are right, we could have done a better job writing a more in-depth migration guide.
I am still closing this issue because I think you fixed the issue yourself.

All 2 comments

I found a section in the JavaScript advanced usage section about filtering events with beforeSend. Should I be using this instead setShouldSendCallback?

It would help if there was a detailed migration guide from react-native-sentry to @sentry/react-native

Yes, beforeSend should be used.
And yes sorry you are right, we could have done a better job writing a more in-depth migration guide.
I am still closing this issue because I think you fixed the issue yourself.

Was this page helpful?
0 / 5 - 0 ratings