Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Ignore Errors does not working #436

Open
eladhaz05 opened this issue Mar 6, 2018 · 7 comments
Open

Ignore Errors does not working #436

eladhaz05 opened this issue Mar 6, 2018 · 7 comments

Comments

@eladhaz05
Copy link

Do you want to request a feature or report a bug?
bug

Has someone had this problem before?
Yes

What is the current behavior?

I want to use ignoreErrors in the config.
I use it like this:
// setting up configuration.
Raven.config('https://' + SentryId.publicKey + ':' + SentryId.secretKey + '@' +
SentryId.host + '/' + SentryId.project,
{ // configuring extra contextual information for the installation.
name:XXXXX,
environment:XXXXXX,
tags:{api:XXXXXXX},
ignoreErrors:[
'BadRequestException:',
'NotFoundException',
'UnauthrizedException'
]
}
)

I still got this errors with those strings

What is the expected behavior?
To get errors without those strings

Thank you

@kamilogorek
Copy link
Contributor

kamilogorek commented Mar 8, 2018

Can you please provide an event that should but is not matching this errors filter?

You can gather them using

Raven.config('__DSN__', {
  dataCallback: function (event) {
    console.log(JSON.stringify(event, null, 2));
  }
})

Cheers!

@adamreisnz
Copy link

adamreisnz commented Mar 13, 2018

I don't think the ignoreErrors configuration exists for the Node client.
It's not documented at all, and #202 implies it has never been built.

I too would prefer support for ignoreErrors though, because it's easier for admins to add lines to simple configuration like that instead of messing with a callback. It's also not documented what format data has that is passed to shouldSendCallback.

@kamilogorek
Copy link
Contributor

Aaaaaghr... I again misread that its raven-js issue. @eladhaz05 for now, please use shouldSendCallback for this purpose.

@adamchainz I totally agree. We are in the process of unifying all JS SDKs and it soon won't be an issue. It'll take a while, but we'll get there soon :)

@adamchainz
Copy link
Contributor

you @'d the wrong adam

@kamilogorek
Copy link
Contributor

Haha, sorry @adamchainz! And thanks for letting me know 🤦‍♂️
cc @adamreisnz

@adamreisnz
Copy link

Hah, similar names :)

@kamilogorek great to hear, look forward to a unified SDK!

@adamreisnz
Copy link

I've written a custom helper for this based on code found in raven-js, you can use it to support ignoreErrors while waiting for the SDK's to be unified.

Helper:

/**
 * Join an array of string/regex patterns into a single regex (adapted from raven-js)
 */
function joinRegex(patterns) {

  //Initialize sources
  const sources = [];

  //Loop patterns
  for (const pattern of patterns) {

    //If it's a string, we need to escape it
    if (typeof pattern === 'string') {
      sources.push(pattern.replace(/([.*+?^=!:${}()|[\]/\\])/g, '\\$1'));
    }

    //If it's a regular expression already, we want to extract the source
    else if (pattern && pattern.source) {
      sources.push(pattern.source);
    }

    //Intentionally skip other cases
  }

  //Return combined regular expression
  return new RegExp(sources.join('|'), 'i');
}

Configuration converter:

if (Array.isArray(cfg.ignoreErrors) && cfg.ignoreErrors.length > 0) {
  const ignoreErrors = joinRegex(cfg.ignoreErrors);
  cfg.shouldSendCallback = function(data) {
    if (data.message && typeof data.message.match === 'function') {
      return !data.message.match(ignoreErrors);
    }
    return true;
  };
}

This essentially defines a shouldSendCallback config property if you've passed ignoreErrors instead.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants